3 Replies Latest reply on Mar 3, 2011 8:25 AM by kglad

    LoadVars question


      When using this code:


      varReceiver1 = new LoadVars();

      varReceiver1.load("//this is a php file");


      varReceiver1.onLoad = function()






      Can I make the loaded variables from the php file be used in another scene or another .swf file?


      For example, I instantiated varReceiver1 in Scene1. In order to use the variables again do I instantiate varReceiver1 again in another scene? What if I wanted to use the variables inside an object? (e.g. inside a movie clip, button, etc.)


      In short, I want to know how to make the loaded variables be global, meaning, I want to be able to use it in other scenes, .swf files, or anywhere else without instantiating it again as it causes a lot of lags since I am dealing with 3000+ variables.



      PS: I get my variables from a php file which sends a string to flash. I am also having a difficult time converting them into numbers. It sometimes give me the value of undefined or NaN.



        • 1. Re: LoadVars question
          kglad Adobe Community Professional & MVP

          variables exist across scenes.  to use variables in an object, you need to use the correct path to the variable from your object.


          or, while not recommended, you can use _global to prefix a variable and then you don't need to use the correct path to your variable.

          • 2. Re: LoadVars question
            Flashnewbie911 Level 1

            Followup question:


            When I load variables from a php file, do i still need to instantiate the variables?


            For example:


            variable A which is a string came from a php file. Can I use variable A right away, without instantiating it to the flash part (B = A), then use B.


            Additionaly, how do I convert string variables into numbers (integer) in flash.



            • 3. Re: LoadVars question
              kglad Adobe Community Professional & MVP

              when loading is complete, the variables are instantiated.  however, when using loadvars, they are defined within the scope of the loadsvars object and not many people like that.  for example:


              var sendLV:LoadVars=new LoadVars();

              var receiveLV:LoadVars=new LoadVars();




              if variable/value data is received from the php, your flash variable is instantiated.  however, to reference it you would use:




              which is a bit cumbersome.  plus, you don't have a listener so you don't exactly know when that variable is received.  so, typically the following is used:



              var sendLV:LoadVars=new LoadVars();

              var receiveLV:LoadVars=new LoadVars();








              function readyToGo(){

              // now you can use yourflashvariable and be sure it's been assigned a value.





              var s:String="123";

              var n:Number=Number(s);


              to convert a fraction to an integer, use Math.round(), or Math.floor() or Math.ceil


              p.s.  use



              trace(src);  // or display src in textfield if you can't see online traces



              when testing.  src will contain all sorts of good debugging info.