Getting a roll over to work properly in Flex is no fun.
Mouse rolls over a tab, then the tab "slides out" revealing a tool bar or something.
There are a few things you need to do to get this working right, let's walk through the steps.
<mx:Canvas y="-55" right="10" height="80" width="600" id="slider">
<mx:Label text="Slider content"/>
</mx:Canvas>
Now you should have a nice canvas with only 25 pixels showing.
private var transitionHappening:Boolean=false;
<mx:Move yFrom="-55" yTo="0" duration="400" target="{slider}" id="moveOut" effectStart="transitionHappening=true;" effectEnd="transitionHappening=false;"/>
<mx:Move yFrom="0" yTo="-55" duration="500" target="{slider}" id="moveIn" effectStart="transitionHappening=true;" effectEnd="transitionHappening=false;" />
Pretty straight forward eh? Moving from -55 to 0 and back, targeting the slider, and setting the boolean off and on. We'll later use this boolean to reduce errors in rolling over and prevent duplicate calls to the rollover and rollout events.
private function init():void{
slider.addEventListener(MouseEvent.ROLL_OVER,rollOver);
}
private function rollOver(event:MouseEvent):void{
if(!transitionHappening){
moveOut.play();
slider.removeEventListener(MouseEvent.ROLL_OVER,rollOver);
slider.addEventListener(MouseEvent.ROLL_OUT,rollOut);
}
}
private function rollOut(event:MouseEvent):void{
if(!transitionHappening){
moveIn.play();
slider.removeEventListener(MouseEvent.ROLL_OUT,rollOut);
slider.addEventListener(MouseEvent.ROLL_OVER,rollOver);
}
}
<mx:Application creationComplete="init()" xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" >
<mx:Script>
private var transitionHappening:Boolean=false;
private function init():void{
slider.addEventListener(MouseEvent.ROLL_OVER,rollOver);
}
private function rollOver(event:MouseEvent):void{
if(!transitionHappening){
moveOut.play();
slider.removeEventListener(MouseEvent.ROLL_OVER,rollOver);
slider.addEventListener(MouseEvent.ROLL_OUT,rollOut);
}
}
private function rollOut(event:MouseEvent):void{
if(!transitionHappening){
moveIn.play();
slider.removeEventListener(MouseEvent.ROLL_OUT,rollOut);
slider.addEventListener(MouseEvent.ROLL_OVER,rollOver);
}
}
</mx:Script>
<mx:Move yFrom="-55" yTo="0" duration="400" target="{slider}" id="moveOut" effectStart="transitionHappening=true;" effectEnd="transitionHappening=false;"/>
<mx:Move yFrom="0" yTo="-55" duration="500" target="{slider}" id="moveIn" effectStart="transitionHappening=true;" effectEnd="transitionHappening=false;" />
<mx:Canvas y="-55" right="10" height="80" width="600" id="slider" backgroundColor="#ff0000">
<mx:Text text="YAY!" />
</mx:Canvas>
</mx:Application>