Avg. Rating 5.0

Problem

Functions are not supported in Flash Lite 1.1, since Flash Lite 1.1 is Flash 4 style syntax and does not support ActionScript 2.0 as in Flash Lite 2.x and above.

Solution

Pseudo functions can be created by utilizing the call() statement to invoke frame labels contained in a non visible off stage movieclip. This movieclip is known as a "function clip" in the Flash (Lite) community.

Detailed explanation

Code reuse and encapsulation are challenging aspects of Flash Lite 1.1 development due to it's high reliance on the timeline and it's lack of support for creating user defined functions, easily.  In Flash Lite 2.x and above, developers enjoy the luxury of the function construct. However, this is not so when developing content targetted for devices supporting Flash Lite 1.1.

Despite this limitation, and lack of the function() contruct in Flash Lite 1.1, it is possible to mimick function like behavior. To do this,one must use what are known as "function clips". These are essentially static movieclips that you place off the visibile stage area for the duration of your Flash Lite 1.1 application. This function movieclip contains individual separate layers, each corresponding to a different function. Each of these can be called during runtime to perform a specific action by running the ActionScript on that particular frame. The call() statement is used to do this. call() is an ActionScript statement which runs the code on an intended frame as specified in the parameter specified in the command.

//-- execute the contents of the frame that is labelled "restart" (on the current timeline)

call( "restart" );

It's important to understand that the call statement executes the frame contents inline to where the current playhead is during execution. So it is different than statements such as gotoAndPlay() and nextFrame().

By utilizing the power of the call statement, and targetting a specific movieclip, it is possible to create pseudo functions contained in a libary in Flash Lite 1.1. The syntax involves targetting both the movieclip and the frame label of the ActionScript to run within that movieclip.

Here is an example of a simple statement that runs a frame label called "restart" that is contained within a library function clip off the visible area of the stage during runtime. Note the full colon which delimits the function clip from the actual function name. This is similar to the syntax used when accessing variables contained within movieclips.

//-- In Flash Lite 1.1, we already have the library_mc movieclip off the visible stage area, which contains a restart layer with a label named "restart"

call( "library_mc:restart" );

It is important to remember to label each frame label in the function movieclip to your correpsonding function names, and to divide the function movieclip into sections such that each layer in the timeline has only it's own ActionScript to run for that specific function. You should not overlap the frames on the timeline for each function within the movieclip.

Typically, within a complex Flash Lite 1.1 application or game, you will have either one or more function clips to help to organize your ActionScript code.


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes