View comments | RSS feed

MMExecute function

MMExecute("Flash JavaScript API command;":String) : String

Lets you issue Flash JavaScript API (JSAPI) commands from ActionScript. In Flash MX2004 the MMExecute function can be called only by a movie that is used as a Flash Panel (file is stored in WindowSWF directory), by an XMLtoUI dialog box, or by the Custom UI of a component. JSAPI commands have no effect in the player, in test movie mode, or outside the authoring environment.

The Flash JSAPI provides several objects, methods, and properties to duplicate or emulate commands that a user can enter in the authoring environment. Using the JSAPI, you can write scripts that extend Flash in several ways: adding commands to menus, manipulating objects on the Stage, repeating sequences of commands, and so on.

In general, a user runs a JSAPI script by selecting Commands > Run Command. However, you can use this function in an ActionScript script to call a JSAPI command directly. If you use MMExecute() in a script on Frame 1 of your file, the command executes when the SWF file is loaded.

For more information on the JSAPI, see www.macromedia.com/go/jsapi_info_en.

Availability: ActionScript 1.0; Flash Player 7

Parameters

command:String - Any command that you can use in a Flash JavaScript (JSFL) file.

Returns

String - A string representation of the result, if any, sent by the JavaScript statement.

Example

The following command will output the number of items in the library of the current document to the trace window. You must run this example as a Flash panel because Flash files can't call MMExecute if they are run in either test movie or the browser.

Now you can select your file from the bottom of the Window > Other Panels menu.

The ActionScript trace function does not work from a Flash panel; this example uses the JavaScript fl.trace version to get the output. It might be easier to copy the results of MMExecute to a text field that is part of your Flash Panel file.


Version 8

Comments


Michael Gioffredi said on Nov 27, 2005 at 3:57 PM :
Running a jsfl command from flash is different from manually selecting it from the Commands menu.

1) Selecting edit>undo after an effect that was executed from the command menu undoes the entire command (good). However selecting edit>undo after a command that was executed from a flash panel steps backwards through each and every step the command took (bad). I have commands that take 1000+ steps so undoing them becomes impossible after they are executed from flash.

2) Large scripts fail. Running the same script from flash, that works when it is executed from the command panel, seems to skip steps. I’m not sure exactly, but possibly steps that run other jsfl commands.

3) Scripts run much slower. Running a script from the command panel took about 5 seconds, while running the same script from flash took about 14 seconds.
Helper Bee said on Nov 30, 2005 at 2:14 PM :
Please note that the URL to use for finding more information on the JS API is no longer accurate.

Instead, go to http://www.macromedia.com/support/documentation/en/flash/ and choose the Extending tab near the middle of the page.
mishmash-jumpcat said on Jan 3, 2007 at 2:04 PM :
Hey...

I've found that I can write some pretty large scripts... even hundreds of lines passed as a single JSFL command string, with success. You just have to escape the special characters very carefully. Also one very important thing that isn't clear in the documentation is that you can't return the value you want to return to the MMExecute caller by using a "return()" statement. For example:

getMyVal = MMExecute('return('myvalue'));
// Doesn't work. We might expect it to return "myvalue"

MMExecute doesn't treat the entire script-string that you pass to it as a function, so that string can't return a value. Counter-intuitive if you ask me.
This is because MMExecute expects to call a function and to return the value of that function back to the caller. So create a function first, then call it, in order to get your custom return value.

getMyVal = MMExecute("function myFunc() { return('myvalue'); } myFunc();"));

This one works. Note that it isn't returning a value from the script... it is returning a value from the function defined in the script. And the last (and only) function to get called was the "myFunc()" function. MMExecute expects that you want the value of that last function call.
juankpro said on Aug 1, 2007 at 9:13 AM :
MMExecute does not only expects to call a function returning a value, what it really does is that returns the value of any code placed in the last line that return code i.e. if the last line is something like this:

var x = 5;

then the value 5 will be returned, that was the original idea and not treating the function as a function. This same approach is used by javascript when called from an HTML link or when called using a getURL function.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00001747.html