Add a frame script (addFrameScript) dynamically in Flash CS3
30 April , 2007
Posted by on It is been around for some time but not so many people actually know already this little undocumented feature in Flash CS3. You can actually add frame scripts dynamically by using the addFrameScript() method. Imagine you want to add some script to the timeline of a movieclip myStar: you can actually do this from the document class like this short code example shows:
package com.newmovieclip{ import flash.display.MovieClip; public class Main extends MovieClip { public var myStar:Star; //constructor public function Main() { //place a star on stage myStar = new Star(); addChild(myStar); //add script to star timeline on frame 5 myStar.addFrameScript(4,frameFunction); // (zero based) } private function frameFunction():void { trace("Executing code for star Frame 5" ); //delete frame script by passing null as second parameter myStar.addFrameScript(4,null); } } }
As you see we can pass the framenumber and the function to be executed when the playhead enters that frame. Sometimes this can be very handy I think. At least to keep all your code in one place as it is a best practice 🙂
You can also see that when you do not want the function to be registered with that specific frame that you can use the same method but just pass null as the second parameter .
So hope this helps you 😉
Awsome mates 🙂 Thanks Ill use this on my new api to make it cooler 🙂 Making one so as3 becomes alot easier with movie clips at least and keyboard events
@ franky : At least with keyboard events 🙂
What you mean ? It has movie clip and key board access plus Im going to add xml socket suppot
Welcome to my site!
My site describes kinds of earnings by means of sponsors!
Thanks!
Why do they NOT make it all official? man. those guys tick me off really bad! It’s like working with Microsoft documentation
tribromophenol somacule cudgeler neronian pretry postspasmodic zwinglian skyman
Big L’s Paintball Plus
http://www.trincoll.edu/orgs/praxis/
Pingback: Undocumented add frame scripts method AS3 « NiK oN FlAsh
Pingback: Undocumented add frame scripts method AS3 « Domy Incorporation
Pingback: addFrameScript and currentLabels | Flash Monkey