ActionScript 3 TransitionManager
February 6, 2009 by: smonteThis tutorial is all about the ActionScript 3.0 TransitionManager. I will explain briefly what the TransitionManager class is and how you can use it your Flash movies.
Intro
The TransitionManager class allows you to apply different animation effects to movie clips. Overall, there are ten different animations available. These are: Blinds, Fade, Fly, Iris, Photo, PixelDissolve, Rotate, Squeeze, Wipe and Zoom. You can see these in action in the movie above.
Setting up the environment
1. Create a new document of size 500×300.
2. Draw a rectangle of size 50×50.
3. Convert the rectangle into a movie clip. Name it “box” and set the registration point to the center.
4. Now drag 10 of these movie clips on to the stage.
5. Give them instance names of “box1″, “box2″, box3″, … , “box10″.
Moving into ActionScript 3
6. Create a new layer for ActionScript and type the following.
//We need for the animations import fl.transitions.*; import fl.transitions.easing.*; //This array will store all the transitions var transitions:Array = new Array(); //Add MOUSE_OVER handlers to each box box1.addEventListener (MouseEvent.MOUSE_OVER, mouseOverBox); box2.addEventListener (MouseEvent.MOUSE_OVER, mouseOverBox); box3.addEventListener (MouseEvent.MOUSE_OVER, mouseOverBox); box4.addEventListener (MouseEvent.MOUSE_OVER, mouseOverBox); box5.addEventListener (MouseEvent.MOUSE_OVER, mouseOverBox); box6.addEventListener (MouseEvent.MOUSE_OVER, mouseOverBox); box7.addEventListener (MouseEvent.MOUSE_OVER, mouseOverBox); box8.addEventListener (MouseEvent.MOUSE_OVER, mouseOverBox); box9.addEventListener (MouseEvent.MOUSE_OVER, mouseOverBox); box10.addEventListener (MouseEvent.MOUSE_OVER, mouseOverBox); //Assign a different transition to each box box1.transition = Blinds; box2.transition = Fade; box3.transition = Fly; box4.transition = Iris; box5.transition = Photo; box6.transition = Rotate; box7.transition = Squeeze; box8.transition = Wipe; box9.transition = PixelDissolve; box10.transition = Zoom; //This function is called everytime the mouse moves over a box function mouseOverBox (e:Event):void { //Store the selected box in a local variable var selectedBox:MovieClip = MovieClip(e.target); //Remove the event listener (the user can't stop the animation once started) selectedBox.removeEventListener (MouseEvent.MOUSE_OVER, mouseOverBox); /* Start a new transition with the following parametes type: We use a transition type that is defined for each box direction: The direction of the animation (Transition.OUT is the second option) duration: Duration of the animation in seconds easing: The type of easing applied to the animation shape: A mask shape. Applies only when using the "Iris" transition */ var myTransitionManager:TransitionManager = new TransitionManager(selectedBox); myTransitionManager.startTransition ({type:selectedBox.transition, direction:Transition.IN, duration:1, easing:Regular.easeOut, shape:Iris.CIRCLE}); //Add the transition to an array, so it won't get garbage collected transitions.push(myTransitionManager); //Add a listener that calls the function animationComplete, when the animation is finished myTransitionManager.addEventListener ("allTransitionsInDone", animationComplete); } //This function is called when a box animation is complete function animationComplete (e:Event):void { //Start listening for the MOUSE_OVER again e.target.content.addEventListener (MouseEvent.MOUSE_OVER, mouseOverBox); }
You are done, test your movie! I must say a couple of words about the “allTransitionsInDone” event. If look for it in the Adobe documentation, you won’t find it. It is a very useful event and I strongly believe it should be documented as well. For more information about the event, see the comments section in TransitionManager – ActionScript 3 Language and Components Reference.
If you have any questions concerning the tutorial, don’t hesitate to ask in the forum.
Related tutorials:
Comments
One Response to “ActionScript 3 TransitionManager”Leave a Reply
You must be logged in to post a comment.
not working :S:S