5 Replies Latest reply on May 29, 2012 4:11 PM by esdebon

    Passing variables to actionscript 2 using javascript

    Tony404 Level 1

      Hi

       

      I have been trying to pass variables to a flash player with out refreshing the page. While do my research I came I cross things like externalinterface and other.

       

      I found a javascript + actionscript code that passed ariables to flash without refreshing page:

       

      So I have flash 8 with actionscript 2.0.

       

      HTML:

       

      <SCRIPT LANGUAGE=JavaScript>

      <!--

      function callJavascript(){

        var sendText = inputValue.vars.value

        window.document.myMovie.SetVariable("testValue", sendText);

      }

      //-->

      </SCRIPT>

       

      <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="550" height="100" id="myMovie" align="middle">

      <param name="allowScriptAccess" value="sameDomain" />

      <param name="movie" value="setplay.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffcc00" /><embed src="setplay.swf" quality="high" bgcolor="#ffcc00" width="550" height="100" name="myMovie" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
      </object>
      </body>
      <p>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=button value="Pass the variable to Flash" onClick="callJavascript()">
      <form name="inputValue">

      <a href="javascript:callJavascript()"> flash one</a><input type="hidden" name="vars" value="1.flv"/>
        </form>
      </html>

       

       

      I have a flash player with a movie player instance  name myVid:

       

      Actionscript:

       

       

      var testValue:String = "";

      watchCallback = function (id, oldval, newval):String {

      result_txt.text = newval;

      myVid.play(newval);

      return newval;

      };

      _root.watch("testValue", watchCallback);

       

      The code gets the vars variable on the html page. Passes vars to actionscript using javascript, displays the text on result_txt and plays a flv video with similar name to passed variable.

       

      The problem is :

       

      I have multiple a href links which I would like to have different variables that they would pass to the flash player.

       

      <a href="javascript:callJavascript()"> flash one</a><input type="hidden" name="var1" value="1.flv"/>

      <a href="javascript:callJavascript()"> flash two</a><input type="hidden" name="var2" value="2.flv"/>

      <a href="javascript:callJavascript()"> flash three</a><input type="hidden" name="var3" value="3.flv"/>

      <a href="javascript:callJavascript()"> flash four</a><input type="hidden" name="var4" value="4.flv"/>

       

      How can I change the code so that if someone clicks flash one the value in var1 is passed to flash.

      and if flash two is clicked var2 is passed to flash.

       

      Thanks.

        • 1. Re: Passing variables to actionscript 2 using javascript
          esdebon Level 4

          this is not the complete example...

           

          You need a javascipt fuction for each value or use id to get the reference of the value

          • 2. Re: Passing variables to actionscript 2 using javascript
            Tony404 Level 1

            HI

             

            Thanks for the reply. So the javascipt function is now.

             

            <SCRIPT LANGUAGE=JavaScript>

            <!--

            function callJavascript(){

               var sendText = inputValue.vars.value

               var sendText1 = inputValue.vars1.value

             

               if(sendText!='')

               {

               window.document.myMovie.SetVariable("testValue", sendText);

               }

               else if(sendtext1!='')

               {

               window.document.myMovie.SetVariable("testValue", sendText);

               }

            }

             

            //-->

            </SCRIPT>

             

            This sucesfully recognises what variable to be passed to actionscript in a multiple variable situation.

            The problem now is how I can sucessfully flick from one ahref to another  .

             

            So lets say I click the first a href it calls the function the variable is passed and all works. If I then click the second the first video just stops and variable is still passed.

             

            Actionscript 2.0 is:

             

            var testValue:String = "";

            watchCallback = function (id, oldval, newval):String {

            result_txt.text = newval;

            myVid.play(newval);

            return newval;

            };

            _root.watch("testValue", watchCallback);

             

            I would like for user to click first a href variable passing variable to player. If user clicks  second a href the a variable is passed replacing old variable the action script is above.

             

            Hope you can help thanks.

            • 3. Re: Passing variables to actionscript 2 using javascript
              esdebon Level 4

              you are calling the same value

               

               

              <SCRIPT>

              //more code

              window.document.myMovie.SetVariable("testValue", sendText);

              //more code

              </SCRIPT>

               

               

              Actionscript 2.0 is:

               

              //more code

               

              _root.watch("testValue", watchCallback);

               

              //more code

              • 4. Re: Passing variables to actionscript 2 using javascript
                Tony404 Level 1

                Hi thanks again for replay

                 

                so:

                 

                window.document.myMovie.SetVariable("testValue", sendText);

                 

                Changes using the if statement with another variable. sendText1 is different variable.

                 

                <SCRIPT LANGUAGE=JavaScript>

                <!--

                function callJavascript(){

                   var sendText = inputValue.vars.value

                   var sendText1 = inputValue.vars1.value

                 

                   if(sendText!='')

                   {

                   window.document.myMovie.SetVariable("testValue", sendText);

                   }

                   else if(sendtext1!='')

                   {

                   window.document.myMovie.SetVariable("testValue", sendText1);

                   }

                }

                 

                //-->

                </SCRIPT>

                 

                I would like to flip. rom 2 different video variables.

                 

                Thanks.