152 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $100+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
new says

Hey!

I have a quick question. I have a main class called A, and another class in the class A called B. How do i get class B to reference stage? When I try to do trace(stage) it returns null.

Jerry

P.S I just noticed that the title of the post is kinda silly, INNER CHILD PROBLEM !!

2309 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 10+ members
  • Has sold $100+ on Envato Market
  • Has been a beta tester for an Envato feature
+5 more
theflyingtinman says
Hey!

I have a quick question. I have a main class called A, and another class in the class A called B. How do i get class B to reference stage? When I try to do trace(stage) it returns null.

Jerry

P.S I just noticed that the title of the post is kinda silly, INNER CHILD PROBLEM !!

Is the instance of class A on the stage? Probably not if B can’t reference it.

Or maybe B is trying to reference the stage after instantiation but before it has been added as a child to A ( the constructor code starts executing right after the call to new ClassB() )

152 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $100+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
new says
Hey!

I have a quick question. I have a main class called A, and another class in the class A called B. How do i get class B to reference stage? When I try to do trace(stage) it returns null.

Jerry

P.S I just noticed that the title of the post is kinda silly, INNER CHILD PROBLEM !!

Is the instance of class A on the stage? Probably not if B can’t reference it.

Or maybe B is trying to reference the stage after instantiation but before it has been added as a child to A ( the constructor code starts executing right after the call to new ClassB() )

K, class B is a scrollBar. Class A is the document class. I create a new scrollBar in the document class. When I try to trace stage in the scrollBar class it doesn’t work. Why?

4247 posts
  • Has been part of the Envato Community for over 6 years
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+5 more
Aw_Shucks says

Did you assign the scrollbar or whatever instance a Class path though Linkage?

152 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $100+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
new says
Did you assign the scrollbar or whatever instance a Class path though Linkage?

No, the scroll bar is created dynamically via api. Diagram of what my classes look like.
Reader.AS
ScrollBar.as

STAGE

I can’t get to stage from ScrollBar.as, I’m sure thats because its nested. But is there a way to get stage from scrollBar.as?

152 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $100+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
new says

sorry for dowble post

99 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+2 more
Palehosefan says

Not sure if it will help you, but if you have the ScrollBar as an Object like a Sprite or a MovieClip, try…

yourMC.root.stage.stageHeight etc

152 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $100+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
new says
Not sure if it will help you, but if you have the ScrollBar as an Object like a Sprite or a MovieClip, try…

yourMC.root.stage.stageHeight etc

What? Just what? Do you use OOP ? I figured it out

152 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $100+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
new says

OK I FIGURED IT OUT , theflyingtinman was the only who knew what he was talking about. Hell I dont’ even know what i’m talking about.


I’m bad at OOP , but I still understand most of it. Thanks again theflyingtinman. Sorry guys for postin

1173 posts
  • Has been part of the Envato Community for over 5 years
  • Located in Australia
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+3 more
Motionreactor says
Not sure if it will help you, but if you have the ScrollBar as an Object like a Sprite or a MovieClip, try…

yourMC.root.stage.stageHeight etc
What? Just what? Do you use OOP ? I figured it out

Hey there’s no need to be aggressive…

So that others can benefit from the answer, what was happening was that ‘stage’ could not be referenced and was null because the child object (scrollbar) had not be added to the stage yet. You must wait for an event to occur before referencing the stage.

addEventListener(Event.ADDED_TO_STAGE, addedToStage);

function addedToStage(e:Event):void { trace(stage.stageWidth); }

by
by
by
by
by
by