
CHAPTER 4: User-Interface Tools Automatic layout 86
You do not need to register the ExtendScript function in the ActionScript environment. Your ActionScript
script can simply call the external function using the
ExternalInterface.call() method:
var res = ExternalInterface.call("myJavaScriptFunction");
When the Flash Player executes the ExternalInterface call, ScriptUI looks for a function with the same
name as a method of the
FlashPlayer element, and invokes it with the specified arguments. In the
context of the function, the JavaScript
this object refers to the FlashPlayer object.
Calling ActionScript functions from a ScriptUI script
From the ExtendScript side, use the FlashPlayer method invokePlayerFunction() to call ActionScript
methods that have been defined within the Flash application:
result = flashElement.invokePlayerFunction ("ActionScript_function_name",
[arg1, ..., argN] );
You can use the optional arguments to pass data (of supported types) to the ActionScript method.
Before you can call any ActionScript function from your Adobe application script, your Flash application
must register that function with the
ExternalInterface object, as a callback from the Flash container. To
register a function, use the
ExternalInterface.addCallback() method:
public static addCallback (methodName:String, instance:Object, method:Function);
This registers a function defined in your Adobe application script named getActionScriptArray():
ExternalInterface.addCallback("getActionScriptArray", this, getActionScriptArray);
Flash Examples
These examples in the Adobe ExtendScript SDK demonstrate how to use the Flash Player:
Automatic layout
When a script creates a window and its associated user-interface elements, it can explicitly control the size
and location of each element and of the container elements, or it can take advantage of the automatic
layout capability provided by ScriptUI. The automatic layout mechanism uses certain available information
about user-interface elements, along with a set of layout rules, to establish a visually pleasing layout of the
controls in a dialog, automatically determining the proper sizes for elements and containers.
Automatic layout is easier to program than explicit layout. It makes a script easier to modify and maintain,
and easier to localize for different languages. It also makes the script automatically adapt to the default
font and font size used by the host application for ScriptUI windows.
UsingFlashPlayer.jsx
Shows how to create a Flash Player, and use it to load a play back a
movie defined in an SWF file.
ActionScriptDemo.jsx
Shows how to communicate between the Adobe application scripting
environment and the ActionScript scripting environment of the Flash
Player.
Comentários a estes Manuais