Archive for 2012年6月

JavaScript and ActionScript can talk to each other via ExternalInterface API. It would be convenient to make this channel ready in the html-template of Flash Builder.

html-template can be found at {Flash Builder installation root path}/sdks/{Application’s default SDK}/templates/swfobject/index.template.html.

Add the following codes to after <body> tag

   <script type="text/javascript">
        function getSWF()
            if (navigator.appName.indexOf("Microsoft") != -1)
                return window["${application}"];
                return document["${application}"];
        function jsLog(param)

getSWF method returns the loaded SWF object. jsLog method is a default JavaScript method for ActionScript to call.

For example, say we implement a method called asLog in ActionScript, which is registered to ExternalInterface as:

ExternalInterface.addCallback("asLog", asLog); 

So, once the application is fired (we set Firefox as the default browser for Flash Builder), we can type the following code in Firefox Firebug console to call SWF’s asLog method:

swfObj = getSWF();

It’s handy to make this little change to Flash Builder’s default html-template.

Read Full Post »