Flex is great! Javascript can be great! What if two great things got together?
This is a simple code hint which shows how to call javascript functions from Flex and pass data back and forth:
MXML Button:
<mx:Button
id = "button"
label = "Click Me!"
click = "handleButtonClick(event:MouseEvent)
/>
Flex Function:
private function handleButtonClick(event:MouseEvent):void
{
var functionName:String = "handleButtonClick";
var returnData:String = ExternalInterface.call(f, "You clicked the button!");
}
Javascript Function:
function handleButtonClick(message)
{
alert(message);
}
That’s really all there is to it. the ExternalInterface.call() handles everything for you.
By the way, if you wanted to actually return data from the javascript function, you’d just do a standard return and it’d be available in the returnData variable in Flex:
function handleButtonClick(message)
{
alert(message);
return "success";
}
