Skip to main content
November 21, 2010
Question

How to access stage instances outside of document class?

  • November 21, 2010
  • 1 reply
  • 807 views

I can access the targetObj instance inside the document class,

but when I try to access it in another .as class,get this error:

Access of undefined property targetObj.

Anyone can help?

This topic has been closed for replies.

1 reply

Inspiring
November 21, 2010

Show code.


November 21, 2010

Basically like this:

In the document class:

VideoPlayer.netStreamClientClass = TsVideoClient;

player.play();

And in the TsVideoClient.as file :

package {
    import fl.video.VideoPlayer;
    import fl.video.VideoPlayerClient;
    import flash.display.DisplayObjectContainer;
    dynamic public class TsVideoClient extends VideoPlayerClient
    {
        public function   TsVideoClient(vp:VideoPlayer)
        {
            super(vp);
        }
        public function someTsFunc(d)
        {
            timeinfo.text = d;//Access of undefined property timeinfo,which is an instance of stage,I can access it in the document class though...

        }
        override public function get ready():Boolean
        {
            return super.ready;
        }
    }
}

Inspiring
November 21, 2010

In principal, in order for an object to gain access to stage this object either has to be placed on display list (by using addChild) or reference to stage must be passed to this object. Because you make TsVideoClient a value of some other property - it will not see the stage.

Even then, objects on doc class display list are not global variables and can be accessed by other classes ONLY if these other classes have reference to doc class or references to objects on doc's display list are passed explicitly.

In your code when you write:

timeinfo.text = d

you ask flash to find textinfo variable that belongs to the scope of TsVideoClient instance which (textinfo) doesn't exist in this class - thus the error.