Flash 8 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript classes > ExternalInterface (flash.external.ExternalInterface) > call (ExternalInterface.call method) | |||
public static call(methodName:String, [parameter1:Object]) : Object
Calls a function exposed by the Flash Player container, passing 0 or more arguments. If the desired function is not available, the call returns null; otherwise it returns the value provided by the function. Recursion is not permitted; a recursive call produces a null response.
If the container is an HTML page, this method invokes a JavaScript function in a <script> element.
If the container is some other ActiveX container, this method broadcasts an event with the specified name, and the container processes the event.
If the container is hosting the Netscape plug-in, you can either write custom support for the new NPRuntime interface or embed an HTML control and embed Flash Player within the HTML control. If you embed an HTML control, you can communicate with Flash Player through a JavaScript interface that talks to the native container application.
Availability: ActionScript 1.0; Flash Player 8
methodName:String - The name of the function to call in the container. If the function accepts parameters, they must appear following the methodName parameter.
parameter1:Object [optional] - Any parameters to be passed to the function. You can specify zero or more parameters, separating them by commas. The parameters can be of any ActionScript data type. When the call is to a JavaScript function, the ActionScript types are automatically marshalled into JavaScript types. When the call is to some other ActiveX container, the parameters are encoded in the request message.
Object - The response received from the container. If the call failed (for example if there is no such function in the container, or the interface was not available, or a recursion occurred, or there was a security issue) null is returned.
The following example calls the JavaScript function sayHello() in the HTML page that contains the SWF. The call is made by using the ExternalInterface.call() method.
import flash.external.*;
var greeting:String;
var btn:MovieClip = createButton(100, 30, 0xCCCCCC);
btn.onPress = function() {
greeting = String(ExternalInterface.call("sayHello", "browser"));
this.mcTxt.text = greeting; // >> Hi Flash.
}
function createButton(width:Number, height:Number, color:Number):MovieClip {
var depth:Number = this.getNextHighestDepth();
var mc:MovieClip = this.createEmptyMovieClip("mc_" + depth, depth);
var mcFmt:TextFormat;
mc.beginFill(color);
mc.lineTo(0, height);
mc.lineTo(width, height);
mc.lineTo(width, 0);
mc.lineTo(0, 0);
mcFmt = new TextFormat();
mcFmt.align = "center";
mcFmt.bold = true;
mc.createTextField("mcTxt", depth, 0, 0, width, height);
mc.mcTxt.text = "Call JS Function";
mc.mcTxt.setTextFormat(mcFmt);
return mc;
}
For the previous example to work properly, you should be copy and paste the following code into the containing HTML page. Unless the HTML page is hosted on a server, your browser may alert you with a security warning.
<script>
function sayHello(name) {
alert(">> Hello " + name + ".");
return ">> Hi Flash.";
}
</script>
Version 8
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/00002203.html
Comments
nuthing.\ said on Dec 12, 2005 at 11:40 AM : No screen name said on Dec 16, 2005 at 7:32 AM : No screen name said on Jan 17, 2006 at 8:11 AM : No screen name said on Feb 14, 2006 at 1:47 PM : doken said on Feb 15, 2006 at 5:37 PM : kossok said on Mar 9, 2006 at 4:37 AM : No screen name said on Mar 12, 2006 at 8:45 PM : MarkDog12 said on Mar 21, 2006 at 11:16 AM : Charles Parcell said on Mar 28, 2006 at 10:52 AM : No screen name said on Mar 30, 2006 at 8:52 AM : daRoost said on May 4, 2006 at 11:40 AM : gareth_cole said on May 18, 2006 at 9:20 AM : NotFFirk said on Jul 20, 2006 at 9:33 AM : AlexWS said on Aug 3, 2006 at 2:56 PM : Lacrymocéphale said on Aug 17, 2006 at 9:41 AM : cybercow said on Sep 13, 2006 at 6:35 AM : No screen name said on Oct 15, 2006 at 12:32 PM : jhannus said on Nov 9, 2006 at 10:58 AM : No screen name said on Nov 15, 2006 at 3:17 AM : ScottyDawg said on Nov 22, 2006 at 1:05 AM : grecu said on Jan 10, 2007 at 3:43 AM : M. Bilal Arshad said on Jan 15, 2007 at 2:50 AM : No screen name said on Jan 16, 2007 at 6:42 AM : Lacrymocéphale said on Apr 11, 2007 at 5:37 AM : No screen name said on May 16, 2007 at 1:09 AM : No screen name said on Jun 1, 2007 at 9:24 AM : No screen name said on Jun 12, 2007 at 2:54 AM : xuzhao said on Jun 13, 2007 at 10:15 PM :