Creating Pseudo Functions in Flash Lite
Is it possible to create functions in Flash Lite 1.1? I'm having problems getting it to work...
This is good question. First off, Flash Lite 1.1 does not support functions. This is a major drawback, as applications, especially games use functions to impart versatility and efficiency. Fortunately, there is a solution to this problem, and it is in the form of the function call():
call(frame);
To illustrate this concept, place a button listener on stage, and enter the following code, by right clicking and selecting options:
on (keyPress "1"){
call("jimmy");
}
In the above code, jimmy refers to the frame name that will we will be executing code from. Now extend the duration of frames to 5 frames. On Frame 5, add:
gotoAndPlay(1);
This guarantees that your movie will be always within frames 1 and 5. Now, add a blank keyframe on frame 6 so that the button is not on stage. Name this frame jimmy. Add the following code:
trace("Code executed!");
Now, compile the code and see for yourself. When you press '1', it will pop up with a message window (in your emulator) saying "Code executed!". This shows that the code from frame 6 was executed. More importantly, it DOES NOT move the movie to that particular frame (your button is still on stage, meaning its still playing between frames 1 and 5). In essence, we are just calling the code from that particular frame, and NOT playing the content of that frame. From CS3 Documentation:
The default form executes the script on the specified frame of the same timeline where the call()
function was executed, without moving the playhead to that frame.
So as you can see, this is pretty much equivalent to creating functions. The only difference is that each labelled keyframe you make represents a different function. For best practice, you can place these at the end of your movie so it doesn't interject anywhere and also helps make your movie more organized.
No comments:
Post a Comment