Javascript from flex

You can call a javascript function from your mxml file by using the ExternalInterface interface ( ExternalInterface.call(“sayHelloWorld”);)

externalinterface.mxml

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute”>
    <mx:Script>
        <![CDATA[
            private function callJavaScript():void
            {
                ExternalInterface.call(“sayHelloWorld”);
            }
        ]]>
    </mx:Script>
    <mx:Button label=”Say ‘Hello World’” click=”callJavaScript();”  x=”67″ y=”63″/>
</mx:Application>

 

and you define your function in the html-template/index.template.html

<script language=”JavaScript” type=”text/javascript“>
    function sayHelloWorld()
    {
        alert(“Hello World, from JavaScript“);
    }
</script>

 

 

Tagged with: , , ,
Posted in Flex, XML

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

HTML tags are not allowed.