2 Replies Latest reply on Sep 28, 2007 8:51 PM by scrfix

    Passing Variables to ActionScript CS3 from JavaScript


      I cannot seem to figure out what I am doing wrong and I need some help . Who better to ask than the experts right?

      I have everything working correctly thus far except for this actionscript. I am using Flash CS3 with ActionScript CS3.

      I have 5 buttons made up in flash.
      I am attempting to do the following tasks
      1. Make buttons with effects in flash - done
      2. Put the correct button in the down position based upon the webpage that the user is on.
      In order to perform this dynamically I apparently have to use 3 different languages, PHP, JavaScript, ActionScript.

      I have been messing with this for a week and cannot figure it out. I have all of the rest of the scripts tested and verified working.

      Here is the link to my test page

      Here is all of my code for testing. (This doesn't include any buttons. This is just merely to test to see if I am passing variables.)

      PHP Code to detect the filename.
      function curPageName() {
      return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
      echo "The current page name detected by PHP is ".curPageName();

      JavaScript Code to pass the variables to Flash
      <script language="javascript" src="swfobject.js">
      var so = new SWFObject("php-url-detection.swf", "php-url-detection", "550", "400", "9", "#FFFFFF");
      so.AddVariable("currentpage","<?php echo curPageName(); ?>")

      ActionScript Code to get Variables from JavaScript and display them in flash.
      // Dynamically Create Text Fields
      var tf:TextField = new TextField();
      tf.autoSize = TextFieldAutoSize.LEFT;
      tf.border = false;

      var tf2:TextField = new TextField();
      tf2.autoSize = TextFieldAutoSize.LEFT;
      tf2.border = false;

      //Create variable to write to page
      var myStr2:String;

      //first attempt at putting the variable onto the page.
      //This LoaderInfo has to be capitlized. An error occurs if not.
      var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters.currentpage;

      //second attempt at putting the variable onto the page
      var myStr:String = this.root.loaderInfo.parameters.currentpage;
      trace (paramObj);
      trace (myStr);

      if (myStr == null)
      myStr = "Flash is not reading the variables from JavaScript. :(";
      myStr2 = " ";
      myStr2 = "Flash is reading the variables from JavaScript!! :)"

      tf.text = myStr; //Display the URL onto the page
      tf2.text = myStr2 //Display Flash is happy

      [-- End of Code --]

      Please help.

      Thank you in advance.