0 Replies Latest reply on Aug 9, 2010 5:25 AM by irockska

    Need to pass variable value from javascript to action script

    irockska

      Hi everyone

       

      I am really stuck here. i have a swf file called text.swf which has two textfield by instance name name_txt which is input text field and anther dynamic textfield called return_txt. and a button . when the button is clicked it sends the text from name_txt to javascript. i am using actionscript 3, and in html file after embedding this file using swfobject, i can pass value from flash to javascript and there is no problem with it, but when i try to call a method in action script and set variable return_txt's text to something its not working, here is my code

       

      //actionscript code

       

      enter_bt.addEventListener(MouseEvent.CLICK,handler);


      import flash.external.ExternalInterface;
      import flash.external.*;

       

      ExternalInterface.addCallback("onChange",onChange );

       

      function handler(evt:MouseEvent):void //this works perfectly
      {   
      //   trace("in event");   
      ExternalInterface.call("general_JS_call", name_txt.text);

      }


      function onChange( str:String ){ //need to callt his method from js
        return_txt.text = str;
           // the return function
      }

       

      //java script code

       

       

      <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

       

      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      <title>demos</title>

       


      <script>
      var me;
      function getID( swfID ){
          //document.writeln("HI");
           if(navigator.appName.indexOf("Microsoft") != -1){
                me = window[swfID];
           }else{
               me = document.getElementById(swfID);
           }
      }

       

       

      function js_to_as( str ){
        
           me.onChange(str); //this is not working
      }

       


      function general_JS_call( str ){
         
           //  val.text = str;
           me.onChange( prompt(str) );
      }
      </script>
      <body onLoad='getID("jsw");'>

       

      <div>
      <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="400" height="300" id="jsw" >
      <param name="jsw" value="text.swf" >
      <param name="allowScriptAccess" value="always" />

       

      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="text.swf" width="400" height="300">
      <!--<![endif]-->
      <a href="http://www.adobe.com/go/getflashplayer">
      <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player">
      </a>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->

       

      <!--  < <EMBED src="text.swf" quality=high bgcolor=#000000  WIDTH=400 HEIGHT=300 NAME=swf
           swLiveConnect=true
          TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">
          </EMBED>-->
      </object>
      </div>
         <input type="button" value="Pass to AS" onClick="js_to_as('Test value');"></input>

       

      </body>
      </html>