Where to put Action Script in Flash, to be called just once on the beginning?
I have a Flash app where I call the first frame over and over. I have a script, that I need to be executed just once at the beginning. Where should i put it? Obvioulsy the first frame isn't a good ide开发者_运维百科a, the script is called to many times. Is there some place for this or some function that would allow me do this?
Thanks
I would put it on the first frame and just keep a variable that check to see if the code had been run the first time around, and if it has been, don't run the code. Post your code though, that'll be helpful.
Maybe a function would be good so we can static the load variable
static var firstLoad:Boolean;
checkLoad();
public function checkLoad(){
if(firstLoad)
{
//run loaded script
}else{
//run first time script
firstLoad = true;
}
}
Will not work for the OP's situation, as OP is using AS2. This is an AS3 way to handle it.
In the constructor of the class definition. Make a class file for the MovieClip and just do whatever you need to do in the constructor function like so.
// in a file called "Foo.as" (replace Foo with whatever you want the classname to be)
package /*your package goes here, if any*/ {
import flash.display.MovieClip;
// The class name should be identical to the name of the file, minus the .as extention
public class Foo extends MovieClip{
// the function name of the constructor is identical to the Class name as well as the file's name minus the .as extention.
public function Foo(){
// This code only happens one time.
}
}
}
Just use that as your class linkage for the movieclip that only needs to execute the script "one time."
精彩评论