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 that's 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
Property inspector to Sending to JS:.
4.
Drag a Button component onto the Stage, position it next to the
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
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);
}
668
Working with External Data
TextInput instance, and set the text property in the Parameters tab of the
TextInput instance, and set its text property in the Parameters tab to
label, and give
out_lbl
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?