1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.events.MouseEvent;
var spos:String = root.loaderInfo.parameters.pos; // This gets the value 'pos' from the URL string.
if (spos == "undefined") { spos = "0"; } // Set it to a default value, incase it wasn't specified.
var Mode:int = parseInt(spos); // It comes in as a String but we want it to be an Integer, so we need to convert it.
// This part just determines the starting position of the animated object.
// This allows us to set different starting positions by changing the URL.
if (Mode == 1 || Mode == -1) { slider.x = 96; }
else if (Mode == 2) { slider.x = 19; }
else { slider.x = 185; }
slider.addEventListener(MouseEvent.CLICK,slide); // Create a trigger for Mouse Click on our object.
stop(); // Stop the script from executing beyond this frame. Not necessary in this case, but it's a habit.
function slide(e:MouseEvent):void {
var SliderTween:Tween; // This will do our animation for us.
// Determine which mode/position the window was last in, then move to the new position.
switch (Mode) {
case 0: // Closed
// Perform the animation using a 'Motion Tween' to gradually change the X position of the item.
// We will start with the original position, specified by 'slider.x' and move to the new position.
// We also want to specify the speed at which the animation will perform (3 seconds in this case).
// Finally, we set our Mode to the new object position.
SliderTween = new Tween(slider, "x", Strong.easeOut, slider.x, 96, 3, true);
Mode = 1;
break;
case 1: // Opening
SliderTween = new Tween(slider, "x", Strong.easeOut, slider.x, 19, 3, true);
Mode = 2;
break;
case 2: // Opened
SliderTween = new Tween(slider, "x", Strong.easeOut, slider.x, 96, 3, true);
Mode = -1;
break;
case -1: // Closing
SliderTween = new Tween(slider, "x", Strong.easeOut, slider.x, 185, 3, true);
Mode = 0;
}
} |
Partager