Search Flex Components Free

Custom Search

July 6, 2009

Calling a JavaScript Function from A Flex Application

Sometimes it might be necessary to call a Javascript function from your Flex application. The technique is quite simple. It involves sending the Javascript function name along with any parameters to the ExternalInterface class. For example, let's assume that a Javascript function called changeMainContent was defined to take a tag name (id) and a url. Normally using Javascript the functions is called this way: changeMainContent(id, url). Let's define a Flex method that invokes this Javascript method:
public function callWrapper(id:String, url:String):void {
var f:String = "changeMainContent";//Javascript function
ExternalInterface.call(f,id, url);
}

Now a call this method when a button is clicked is as follows:

Related Flex Tutorials