Calling Anonymous JavaScript Function From Flex


 

Calling Anonymous JavaScript Function From Flex

In flex application, you can call javascript function defined in html file where your flex file is embed.

In flex application, you can call javascript function defined in html file where your flex file is embed.

Calling Anonymous JavaScript Function From Flex

In flex application, you can call javascript function defined in html file where your flex file is embed. But you can also call an anomymous javascript function defined in ActionScript file.

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Script>

<![CDATA[

import mx.controls.Alert;

import flash.external.*;

private function callJS():void {

if (ExternalInterface.available) {

var returnFromFunctionCall:String = (ExternalInterface.call("function() { alert('Anonumous function call.'); return 'success' }"));

Alert.show("JavaScript Function returned String: "+returnFromFunctionCall);

} else {

Alert.show("Failed.");

}

}

]]>

</mx:Script>

<mx:Button label="Call JavaScript Anonymous Function" click="callJS()"/>

</mx:Application>

Running the application presents output as below:

Clicking on the button calls javascript function which creates alert box as below:

The function returns value 'success'. Click OK button. You will see the output as below:

Ads