4 Replies Latest reply on Sep 26, 2006 9:54 AM by Smitchmor

    FLEX and Javascript

    Abhi910
      Hello All,

      I am new to FLEX and i was trying to integrate flex with javascript.

      Here is my .swf code :
      <?xml version="1.0"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">
      <mx:Script>
      import flash.external.*;
      public function myFunc():Number {
      return 42;
      }
      public function initApp():void {
      ExternalInterface.addCallback("myFlexFunction",myFunc);
      }
      </mx:Script>
      </mx:Application>

      And here is the HTML code that has the javascript and the embedded .swf file
      <SCRIPT language='JavaScript' charset='utf-8'>
      function callApp() {
      var x = worldcup.myFlexFunction();
      alert(x);
      }
      </SCRIPT>
      <BODY>
      <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase=" http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="755" height="400" id="worldcup">
      <param name="allowScriptAccess" value="sameDomain" />
      <param name="src" value="c:\jsSample.swf" />
      <embed src="c:\jsSample.swf" quality="high" bgcolor="#ffffff" width="755" height="400" name="worldcup" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage=" http://www.macromedia.com/go/getflashplayer" />
      </object>
      <button onclick="callApp()">Call App</button>
      </BODY>

      But when i click the button on the HTML, i get a javascript error.

      Could anyone please help. i would really appreciate your help.

      Thanks
      Abhi