4 Replies Latest reply on Apr 20, 2006 9:17 PM by hushhurt

    simple noob question

    hushhurt
      hello - i am new to actionscript, and i may be completely overlooking something obvious.
      what i am trying to do is access a variable within a different timeline from the main. i create a movieclip, within the mc i create a variable named x, but when i try and trace that variable from the main timeline, it says it is undefined.

      in the movieclip i assign "var x:Number = 5"

      in the main timeline i try and trace the variable with "trace(movieClipName.x)" and get an undefined.

      when i trace the variable from the moveclip timeline - it outputs "5"

      what am i missing here - it seems so easy, but i feel so slow.

      thank you
        • 1. Re: simple noob question
          dex002 Level 1
          hey dude, the only variables that are available across multiple timelines are _global vars or vars declared in an class.

          this will work if you get it or set it on any timeline:

          _global.x = 5

          Note that you cannot use data typing with _global vars, so this will throw an error:

          var _global x:Number = 5
          • 2. Re: simple noob question
            Level 7
            Probably the movie clip's first frame has not played. A simple solution is
            to access the on the frame after it is attached to the timeline.


            --
            Lon Hosford
            www.lonhosford.com
            May many happy bits flow your way!
            "hushhurt" <webforumsuser@macromedia.com> wrote in message
            news:e29dbg$t2f$1@forums.macromedia.com...
            hello - i am new to actionscript, and i may be completely overlooking
            something obvious.
            what i am trying to do is access a variable within a different timeline
            from
            the main. i create a movieclip, within the mc i create a variable named x,
            but
            when i try and trace that variable from the main timeline, it says it is
            undefined.

            in the movieclip i assign "var x:Number = 5"

            in the main timeline i try and trace the variable with
            "trace(movieClipName.x)" and get an undefined.

            when i trace the variable from the moveclip timeline - it outputs "5"

            what am i missing here - it seems so easy, but i feel so slow.

            thank you


            • 3. Re: simple noob question
              Level 7

              "hushhurt" <webforumsuser@macromedia.com> wrote in message news:e29dbg$t2f$1@forums.macromedia.com...
              > hello - i am new to actionscript, and i may be completely overlooking
              > something obvious.
              > what i am trying to do is access a variable within a different timeline from
              > the main. i create a movieclip, within the mc i create a variable named x, but
              > when i try and trace that variable from the main timeline, it says it is
              > undefined.
              >
              > in the movieclip i assign "var x:Number = 5"
              >
              > in the main timeline i try and trace the variable with
              > "trace(movieClipName.x)" and get an undefined.
              >
              > when i trace the variable from the moveclip timeline - it outputs "5"
              >
              > what am i missing here - it seems so easy, but i feel so slow.

              Don't declare your variable as 'var' because that makes it a local variable.
              tralfaz


              • 4. Re: simple noob question
                hushhurt Level 1
                sweet - thanks everyone