Skip to main content
Inspiring
August 15, 2012
Answered

Use of a ToggleSwitch inside a Scroller

  • August 15, 2012
  • 3 replies
  • 631 views

The ToggleSwitch introduced in 4.6 looks like a great component that really gives a mobile feel to what would otherwise be a simple checkbox.  While I am somewhat dissapointed that a new skin is required to set the selected and unselected labels, I can get through that.

The issue I am having is with the use of a ToggleSwitch inside a Scroller.  If you place a ToggleSwitch inside a Scroller and fill the rest of the scroller with enough content, then the vertical scrolling action of the Scroller will interfere with the ToggleSwitch's horizontal scrolling.  While using the ToggleSwitch to move from left to right, if the user barely moves up or down, then the Scroller will scroll.  This will break the interaction with the ToggleSwitch.  Usually this will snap the ToggleSwitch to the closest position, left or right.  However, many times the ToggleSwitch's thumb is within the middle 2/3 of the ToggleSwitch.  In this case, the thumb will hang in the middle of the switch!

This can be very confusing for a user, as their selection will not be completed.  While it may appear that the ToggleSwitch has no selection, or is even (just almost) in the selected/unselected state... it could very well be in the opposite state.

Has anyone found any kind of workaround to this issue?

This topic has been closed for replies.
Correct answer ChristopherTotty

Thanks for the reply.  I think my explanation might have been a little off.  It sounds like your solution would be for scrolling into a ToggleSwitch, not out of the ToggleSwitch.  Still, it got me thinking of another method that looks to work.

I turn off the scroller's vertical scrolling while the switch is in use, and then turn it back on when the switch is finished.  I also force a reset of the switch's selection if the user mouses out of the switch.  This keeps it from getting visually hung between selected/unselected.

protected function toggleSwitch_MouseDown(event:MouseEvent):void

                              {

                                             scrollerContent.setStyle('verticalScrollPolicy', ScrollPolicy.OFF);

                              }

                              protected function toggleSwitch_MouseOut(event:MouseEvent):void

                              {

                                             scrollerContent.setStyle('verticalScrollPolicy', ScrollPolicy.ON);

                                             toggleSwitch.selected = toggleSwitch.selected;

                              }

                              protected function scrollerContent_MouseUp(event:MouseEvent):void

                              {

                                             scrollerContent.setStyle('verticalScrollPolicy', ScrollPolicy.ON);

                              }

3 replies

Inspiring
August 17, 2012

Anyone have an idea?

Mark.fromOP
Inspiring
August 19, 2012

Seems like you need to listen for the vertical scroll and if so numb the switch.

Perhaps add a timer function when the user touches your scroller start the timer and listen for finger location from update to update, if the finger is moving on the y axis then dont allow the toggle switch to engage.

Also wouldn't the user have to scroll over the toggle switch not just anywhere on the screen to engage it? Don't understand how it switches when the user is interacting with the screen away from switch.

ChristopherTottyAuthorCorrect answer
Inspiring
August 20, 2012

Thanks for the reply.  I think my explanation might have been a little off.  It sounds like your solution would be for scrolling into a ToggleSwitch, not out of the ToggleSwitch.  Still, it got me thinking of another method that looks to work.

I turn off the scroller's vertical scrolling while the switch is in use, and then turn it back on when the switch is finished.  I also force a reset of the switch's selection if the user mouses out of the switch.  This keeps it from getting visually hung between selected/unselected.

protected function toggleSwitch_MouseDown(event:MouseEvent):void

                              {

                                             scrollerContent.setStyle('verticalScrollPolicy', ScrollPolicy.OFF);

                              }

                              protected function toggleSwitch_MouseOut(event:MouseEvent):void

                              {

                                             scrollerContent.setStyle('verticalScrollPolicy', ScrollPolicy.ON);

                                             toggleSwitch.selected = toggleSwitch.selected;

                              }

                              protected function scrollerContent_MouseUp(event:MouseEvent):void

                              {

                                             scrollerContent.setStyle('verticalScrollPolicy', ScrollPolicy.ON);

                              }