EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 668

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
668 Working with External Data
The following sections contain examples that use the External API:
“Creating interaction with the External API” on page 668
“Controlling Flash Video with the External API” on page 671
Creating interaction with the External API
You can create interaction between the browser and a SWF file thats embedded on a web
page. The following procedure sends text to the HTML page that contains the SWF file, and
the HTML sends a message back to the SWF file at runtime.
To create the Flash application:
1. Create a new Flash document and save it as extint.fla.
2. Drag two TextInput components onto the Stage and give them instance names of in_ti
and out_ti.
3. Drag a Label component onto the Stage, assign it an instance name of out_lbl, position it
above the
out_ti TextInput instance, and set the text property in the Parameters tab of the
Property inspector to Sending to JS:.
4. Drag a Button component onto the Stage, position it next to the out_lbl label, and give
it an instance name of send_button.
5. Drag a Label component onto the Stage, assign it an instance name of in_lbl, position it
above the
in_ti TextInput instance, and set its text property in the Parameters tab to
Receiving from JS:.
6. Add the following ActionScript to Frame 1 of the main Timeline:
import flash.external.ExternalInterface;
ExternalInterface.addCallback("asFunc", this, asFunc);
function asFunc(str:String):Void {
in_ti.text = "JS > Hello " + str;
}
send_button.addEventListener("click", clickListener);
function clickListener(eventObj:Object):Void {
trace("click > " + out_ti.text);
ExternalInterface.call("jsFunc", out_ti.text);
}

Table of Contents

Related product manuals