AS3 Animator Class August 23, 2008
Posted by Mark in Actionscript 3.0.Tags: actionscript, Actionscript 3.0, animator-class, AS3, learn
trackback
I discovered this today while working on my latest project at work. I was trying to find a way that you could set up a motion tween with filters on a movie clip and that’s exactly what I got. I’m talking about the Animator class. You can create one, just like you would create any other variable like this:
var myAnimator:Animator = new Animator(xml, displayObject);
In place of the xml, you put the name of your xml file, and in place of the displayObject you put your reference to your display object (a movie clip, sprite, etc). Then you have to write some XML…. OR you create a motion tween just like you normally would using the timeline and your symbol and whatever filters you want to use, then you select the frames in the timeline that have your tween, and you right click, and select Copy Motion as AS3.0. It will ask you for the instance name of the object that you want to apply this tween to later in your code. Now the code is literally copied to your computer’s clip board, so you have to paste it somewhere. Open up your actions panel and do so. What you get will look something like this:
import fl.motion.Animator;
some XML
var myMC_animator:Animator = new Animator(myMC_xml, myMC);
myMC_animator.play();
What that does is create an XML file that has the settings for your motion tween. Why Adobe made it an XML file, I have no idea, but it’s really quite handy if you think about it. Instead of making your XML right in your flash project, you could make it as a standalone XML file, then you could use a loader to load in that XML file use the resulting motion tween on your symbols. You would do that to make your flash project configurable by some means other than flash. That way, lets say that the web developer in your company is integrating your new flash project into the company website. Now he can control all of the settings in the motion tween, which could be used as button rollover effects, or any other use for a motion tween.
Some other notes about using them, if you’re using them inside a funtion, make sure you declare them outside of the function, otherwise when the function completes it’s garbage collection will delete the animator variable, and the symbol that it was applied to will be stuck 1 frame into the tween. You can have multiple filters in the XML file, and you can even tween the quality setting. Once you’re looking at the XML file I think it’s pretty self explanatory to what you need to do to make it suit your needs.

