Browse DevX
Sign up for e-mail newsletters from DevX


Extending Flash MX 2004, Part 3: Using History and Flash Panels for Faster Development : Page 3

The History Panel is one of the best learning tools for Flash—if you know how to take advantage of the information it stores. Learn the History panel as well as how to make your own Flash panels.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

ActionScript and JSFL
Flash movies that run in the Flash MX 2004 IDE can execute a string of JSFL using a special ActionScript function. Which means that your Flash panels and XML2UI dialog boxes that contain Flash movie controls can modify/update the Flash document from a Flash movie. The JSFL code you execute can also return a value back to ActionScript. The ActionScript function is called MMExecute, and it can be used anywhere in your Flash movie.

The syntax is simple:


For example, I can create a new panel, as above, and in the Flash movie for that panel, I can execute a string of JSFL that will delete a layer when a button is pressed.

Here is the ActionScript to do it:

MyButton.addEventListener("click",this) This.click=function() { MMExecute("flash.getDocumentDOM().getTimeline().deleteLayer();") }

When the button is pressed, the MMExecute function passes the JSFL string as an argument to the Flash MX 2004 JSAPI Interpreter, which then runs the JSFL code in exactly the same way that a Command is run.

It is also possible to access the value of a JSFL property because the MMExecute function will return a value. So if I wanted to check that the computer running my Flash panel is currently connected to the Internet, I could use the following ActionScript:


In the above code, the ActionScript variable 'hasInternetConnection' will contain a Boolean value that it received from the JSAPI Interpreter.

MMExecute will wait for a return value before it runs the next line of code in your ActionScript.

It is recommended that if you want to execute a large JSFL script from ActionScript, you should place the JSFL script in an .jsfl file and then use the 'flash.runScript' function to execute the JSFL script within that file.

Here is an ActionScript function that will execute the JSFL code within a .jsfl file:

function executeLargeJSFLScript(fileURI) { return MMExecute("fl.runScript('"+fileURI+"');") }

And you can use it like this:


Notice, that the fileURI in the above example, doesn't contain backslashes; it contains forward slashes and a file:/// protocol prefix.

The following would be incorrect:


This is a common mistake. All the functions that are exposed in the JSFL scripts—that accept a fileURI as an argument, such as 'flash.saveDocumentAs'—require the string to contain a file:/// protocol prefix and to contain forward slashes instead of backslashes.

One really useful implementation of MMExecute would be getting a Flash movie that is running in the Flash MX 2004 IDE to work with regular expressions. As ActionScript doesn't support regular expressions, it is possible to send them the JSAPI Interpreter using MMExecute and the return value(s) will be returned to ActionScript.

Guy Watson (or FlashGuru as he is also known) has been an active, well recognized figure in the Flash community for four years, supporting the community with tutorials, source files, forum moderation, and running his own Flash resource Web site, FlashGuru's MX 101. Guy was one of two developers who created the ever popular, award winning zoom interface for Relevare and now works for the leading entertainment company Endemol UK, the creative force behind reality television, producing programs such as Big Brother and The Salon. Guy now spends most of his time developing Flash games and applications for high profile clients such as Channel 5 Television, Ladbrookes, and UK Style.
Thanks for your registration, follow us on our social networks to keep up-to-date