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
Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

ToggleSwitch MOVE event bug?

Trying to get the ToggleSwith control to properly work:

 

private var toggle : ToggleSwitch = new ToggleSwitch();

...

this.toggle.selected = true;
this.toggle.addEventListener( SliderEvent.MOVE, ToggleChange );
// set position
this.addChild( this.toggle );

..
///////////////////////////////////
private function ToggleChange( event : Event ) : void
{
  trace( 'ToggleChange ' + this.toggle.selected );
}

 The ToggleChange method never gets called.

 

However, if I listen to SliderEvent.END, the ToggleChange method does get called, but the toggle.selected value is not set yet, so I had to:

 

///////////////////////////////////
private function ToggleChange( event : Event ) : void
{
  var timer:Timer = new Timer( 500, 1 );
  timer.addEventListener( TimerEvent.TIMER_COMPLETE, ToggleDone );
  timer.start();
}

///////////////////////////////////
private function ToggleDone( event : Event ) : void
{
  trace( 'Toggle ' + this.toggle.selected );
}

 Seems anything faster the 1/2 second (500ms) is too soon to get the value correct.

 

This is a long (and poor) work around.

 

Has anyone had any success with this before I report it as an "issue"?

 

 

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

Re: ToggleSwitch MOVE event bug?

hey jtegen,

 

yah i can confirm that anything slower than a flick will result in incorrect responses from the toggle switch. im going to have to assume when they created the toggle they intended on fingers switching the toggle instantly and not in a slow manner (like our mices.) although this would cause a real world problem should the user move the toggle in slow pace so definitely a bug worth reporting. here is the code i ran to confirm:

 

 

package
{
	import flash.display.Sprite;
	
	import qnx.ui.buttons.ToggleSwitch;
	import qnx.ui.events.SliderEvent;
	
	// The following metadata specifies the size and properties of the canvas that
	// this application should occupy on the BlackBerry PlayBook screen.
	[SWF(width="1024", height="600", backgroundColor="#cccccc", frameRate="30")]
	public class ToggleTest extends Sprite
	{
		private var toggle:ToggleSwitch;
		
		public function ToggleTest()
		{
			toggle = new ToggleSwitch();
			
			toggle.addEventListener(SliderEvent.START, startToggle);
			
			addChild(toggle);
			
		}
		public function startToggle(e:SliderEvent):void
		{
			trace("Started.");
			toggle.addEventListener(SliderEvent.END, endToggle);
		}
		public function endToggle(e:SliderEvent):void
		{
			trace("Ended.");
			trace(toggle.selected.toString());
			toggle.removeEventListener(SliderEvent.END, endToggle);
		}
	}
}

 

 

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
Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: ToggleSwitch MOVE event bug?

hey,

 

for anyone subscribed to this thread there's a workaround for the toggle switch bug in the following thread:

 

http://supportforums.blackberry.com/t5/Tablet-OS-SDK-for-Adobe-AIR/Possible-bug-with-qnx-ui-buttons-...

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