5 Replies Latest reply on May 12, 2006 2:20 PM by abeall

    global variables...

    rangewalker
      ok, this is probably a stupid question that i should know the answer to, but....

      when i poplate variables with values inside of a function i cant access those values outside of the function. what am i doing wrong?

      thanks in advance,

      doc
        • 1. Re: global variables...
          Level 7
          "rangewalker" <webforumsuser@macromedia.com> wrote in message
          news:e427kh$p1d$1@forums.macromedia.com...
          > ok, this is probably a stupid question that i should know the answer to,
          > but....
          >
          > when i poplate variables with values inside of a function i cant access
          > those
          > values outside of the function. what am i doing wrong?
          >
          > thanks in advance,
          >

          http://livedocs.macromedia.com/flash/mx2004/main_7_2/00000785.html

          Check out the link above, it explains it all.

          AB


          • 2. Re: global variables...
            kglad Adobe Community Professional & MVP
            you're using the var keyword to prefix your variable declaration???
            • 3. Re: global variables...
              rangewalker Level 1
              ok, the article explained it pretty well. but when i run the followin i still get a return of 'undefined':

              var snd:Sound = new Sound();
              snd.loadSound("1.mp3",false);
              snd.onLoad = function(){
              //trace(snd.duration);
              _global.myTime = snd.duration;
              }
              trace(_global.myTime);
              • 4. Re: global variables...
                Level 7

                "rangewalker" <webforumsuser@macromedia.com> wrote in message
                news:e429ov$rof$1@forums.macromedia.com...
                > ok, the article explained it pretty well. but when i run the followin i
                > still
                > get a return of 'undefined':
                >
                > var snd:Sound = new Sound();
                > snd.loadSound("1.mp3",false);
                > snd.onLoad = function(){
                > //trace(snd.duration);
                > _global.myTime = snd.duration;
                > }
                > trace(_global.myTime);
                >

                Try:

                _global.myTime;
                var snd:Sound = new Sound();
                snd.loadSound("1.mp3", false);
                snd.onLoad = function() {
                _global.myTime = snd.duration;
                }
                trace(_global.myTime);

                or if you don't need myTime in _global scope then just do the following

                var myTime:Number;
                var snd:Sound = new Sound();
                snd.loadSound("1.mp3", false);
                snd.onLoad = function() {
                myTime = snd.duration;
                }
                trace(myTime);


                • 5. Re: global variables...
                  abeall Level 3
                  It returns undefined because it is not being defined untill *after* onLoad, where as the trace action is executed immediantly.