5 Replies Latest reply on Mar 29, 2010 8:59 AM by Ned Murphy

    Variable question

    celebritymusic Level 1

      Hi

       

      I have a variable, globals.data.ballheight that controls a graphic object.  It gets set in frame 2, and used later on in the timeline.  It works fine - if I set globals.data.ballheight=2; on frame 2, the ball does what I want.

       

      Next, I wanted to use a .txt file to store the variable, and bring it into Flash, which I have successfully set up - if I set the variable to "2" in the .txt file, and then in as3 on line 1 of frame 2 add the line trace(globals.data.ballheight); Flash outputs "2".  In other words, by the beginning of frame 2, it's getting the variable.

       

      However, the ball no longer works correctly.

       

      Any ideas why the imported variable, even though it still ==2 (on frame 2), no longer does what it is supposed to.  Yet, if I manually type in globals.data.ballheight=2 on frame 2, it works fine?

       

      Thanks for your time guys.

       

      Shaun

        • 1. Re: Variable question
          Ned Murphy Adobe Community Professional & MVP

          As long as you're sure the text file has loaded by the time you're trying to use it, then the next possible problem might be that the value is a String until you cast it as a numeric value.

          2 people found this helpful
          • 2. Re: Variable question
            celebritymusic Level 1

            I think that's on the right track Ned

             

            globals.data.eTP = evt.target.data.ballHeight;   gives me a value of 4 if I trace(globals.data.eTP), but functions later on in Flash don't recognise the 4.

             

            However, if I say...

             

            ballHeightVar:Number = evt.target.data.ballHeight;

            globals.data.eTP = ballHeighVar;

             

            ...the functions do recognise the 4, and work correctly.

             

            so is there a more efficient way to write...

             

            globals.data.eTP = evt.target.data.ballHeight;

             

            ...and tell it it's a number, not a string it's receiving?  I tried globals.data.eTP:Number, but Flash didn't like that.

             

            Thanks for your help Ned.

             

            Shaun

            • 3. Re: Variable question
              Ned Murphy Adobe Community Professional & MVP

              Try:

               

              globals.data.eTP = Numer(evt.target.data.ballHeight);

              1 person found this helpful
              • 4. Re: Variable question
                celebritymusic Level 1

                OMG that's satisfying - I've spent the better part of four hours playing with the code

                .

                Thanks once more Ned

                 

                ps - small spelling mistake - Numer should be Number in case anyone else is after the code.

                • 5. Re: Variable question
                  Ned Murphy Adobe Community Professional & MVP

                  You're welcome... Either my fingers are losing it or my keyboard is...  The keyboard is the prime suspect though--it is a temp

                  1 person found this helpful