Home Tutorial Flex Flex-components Calling Anonymous JavaScript Function From Flex

 
 

Calling Anonymous JavaScript Function From Flex
Posted on: July 13, 2010 at 12:00 AM
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:

Calling Flex Function From JavaScript
Sometimes, you may need to call flex function from JavaScript to pass value in the flex application
 
JavaScript call from flex application
In flex application, you may have called function defined in action script
 

Related Tags for Calling Anonymous JavaScript Function From Flex:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.