3 Replies Latest reply on Aug 21, 2007 8:39 AM by SymTsb

    cannot access stage properties from AS3 class

      please take a look at the attached code. it's throwing this compiler error:

      1120: Access of undefined property stage

      any ideas why?

        • 1. Re: cannot access stage properties from AS3 class
          SymTsb Level 2
          The Stage class doesn't exactly work as you might expect. Every display object has a "stage" member which gives it access to the stage classes methods and properties. If you want to check the frameRate of the root clip do so like this...


          This should return the frame rate for the main swf.

          I just had to battle with the issue while trying to center loaded content on the stage. Stage is only used "loosely" in AS3 and as far as I can tell only refers to the lowest level display object which in AS2 would have been called _level0 or root.

          Each DisplayObject (Bitmap, Flash Video, etc) and DisplayObjectContainer (MovieClip, Sprite, etc) has access to the Stage class from it's own stage property. I have tried numerous calls to test and nested levels made no difference on what stage meant. If the call was 3 levels deep (3 external swf calls down), it always reference the top level swf (root) timeline not the parent timeline for which the call was located. Keep this in mind when trying to get numeric results if you aren't getting exactly what you'd expect. It drove me mad last night.
          • 2. Re: cannot access stage properties from AS3 class
            richtextformat Level 1
            cool SymTsb, that works a treat. question: why does not the documentation make this clear? or did i just rush-mis-read it?

            i have a getter in my main Application class that returns the root mc as 'context' so i don't need to cast the thing, this line works perfectly:


            all hail SymTsb


            • 3. Re: cannot access stage properties from AS3 class
              SymTsb Level 2
              The documentation for Flash CS3 does not make this clear at all. It wasn't until I read the Stage class documentation that I even remember reading that there is only one stage per display list which means only the root container (master swf) actually has a stage value. You can bury as much inside a file as you like but you're still left with only one stage. I really wish they'd have put this small tidbit of information inside the "Understanding the Display List" stuff. Would have been very very helpful.

              Please no applause. I'm really quite shy.

              You're are welcome though.