Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Contributor
Posts: 11
Registered: ‎04-01-2008
My Device: Not Specified

Possible bug with qnx.ui.buttons.ToggleSwitch

I may have found a bug with the qnx ToggleSwitch class.

 

I register the Slider.END on a toggle switch and noticed that the value of selected was not what I actually set the toggle to sometimes. 

 

If you move the slider and let go, you read the value it just got set to (expected). 

 

But if you just click on the opposite end to toggle the value, you actually read the old value while the animation slides the button over.  The event is triggered before the animation is done so you end up reading the old value rather than the new value it ends up on.  So my application thinks its false when the value eventually becomes true and vice versa.  But you can't program around the inconsistency.  I would have to capture the event and then schedule a future event to check what you set it to which is annoying.  I need to know when the value was changed and take some action and I haven't found a consistent way to do that.

 

Is this a bug or does someone know how to read the value you just set the toggle to consistently?  I assume Slider.END is the right event and seems to me the value you read out of selected field should not depend on whether animation is going to happen or not.

 

Thanks.

Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Possible bug with qnx.ui.buttons.ToggleSwitch

Hey morpheus,

Yeah we noticed the bug and reported it via the issue tracker page. The bug occurs when you swipe the toggle too slowly and also when u click instead of doing a swipe. It was discussed in the following thread:

http://supportforums.blackberry.com/t5/Tablet-OS-SDK-for-Adobe-AIR/ToggleSwitch-MOVE-event-bug/m-p/6...

Hope that helps!
J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Highlighted
Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Possible bug with qnx.ui.buttons.ToggleSwitch

hey morpheus (and anyone curious),

 

i found a work around for the ToggleSwitch object that works 100% from the tests i've run. Instead of retreiving the ToggleSwitch.selected property I am retreiving the ToggleSwitch.value property which is the position of the slider (cover) at any given time. I created two listeners (eventaully 3 but the last one gets removed after the event is done). First lisetener is for the SliderEvent.START to account for a swipe action and the second listener is for the MouseEvent.CLICK to account for a click or touch event.

 

now based on the final position and value of the ToggleSwitch.value property i took the inverse of the value to predict where the ToggleSwitch.selected would end up. here's the code:

 

ToggleSwitchTest.as:

 

 

package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.MouseEvent;
	
	import qnx.ui.buttons.ToggleSwitch;
	import qnx.ui.events.SliderEvent;
	
	public class ToggleSwitchTest extends Sprite
	{		
		private var toggle:ToggleSwitch;

		public function ToggleSwitchTest()
		{
			super();
			
			// support autoOrients
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			toggle = new ToggleSwitch();
			
			/*
			 * We are accounting for both actions slide and click
			*/
			
			toggle.addEventListener(SliderEvent.START, startToggle);
			toggle.addEventListener(MouseEvent.CLICK, clickChange);
			
			addChild(toggle);
			
		}
		public function clickChange(e:MouseEvent):void
		{
			/*
			 * This function receives the MouseEvent.Click event when the user
			 * decides to click on the slider instead of swiping it
			 * The value is the ending position of the slider not
			 * not revealed selection so we have to do an inverse of the
			 * ToggleSwitch's value (e.g. 0 == False and 100 == True);
			*/
			trace("Click Result: " + !(toggle.value));
		}
		public function startToggle(e:SliderEvent):void
		{
			/*
			 * We have to start listening to the END event to find
			 * the final position of the ToggleSwitch
			*/
			toggle.addEventListener(SliderEvent.END, endToggle);
		}
		public function endToggle(e:SliderEvent):void
		{
			trace("Ended: " + toggle.value);
			
			/*
			 * Depending on the last position of the slider switch, the value
			 * is between 0 and 100. If the last position is between 
			 * 0 and 49 the slider goes to poistion 1 (True) but when
			 * the slider is on the 1 (True) the ToggleSwitch's actual selection
			 * is 0 (False) (toggle.value = slider position)
			*/
			if (toggle.value < 50)
			{
				trace("Value should be FALSE");
			}
			else
			{			
				/*
				* Depending on the last position of the slider switch, the value
				* is between 0 and 100. If the last position is between 
				* 50 and 100 the slider goes to poistion 0 (False) but when
				* the slider is on the 0 (False) the ToggleSwitch's actual selection
				* is 1 (True) (toggle.value = slider position)
				*/
				trace("Value should be TRUE");
			}
			toggle.removeEventListener(SliderEvent.END, endToggle);
		}

	}
}

 

again the results are accurate every time and should get the job done until they come out with a fix for the SliderEvent. let me know how it goes for you. Good luck guys!

 

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman