152 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Sold between 100 and 1 000 dollars
  • United States
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
  • Beta Tester
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 6-7 years
  • Referred between 10 and 49 users
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Sold between 100 and 1 000 dollars
  • United States
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
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Sold between 100 and 1 000 dollars
  • United States
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
  • Attended a Community Meetup
  • Bought between 10 and 49 items
  • Contributed a Blog Post
  • Exclusive Author
  • Has been a member for 5-6 years
  • Sold between 10 000 and 50 000 dollars
  • United States
Aw_Shucks says

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

152 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Sold between 100 and 1 000 dollars
  • United States
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
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Sold between 100 and 1 000 dollars
  • United States
new says

sorry for dowble post

99 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 6-7 years
  • Referred between 1 and 9 users
  • Sold between 1 000 and 5 000 dollars
  • United States
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
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Sold between 100 and 1 000 dollars
  • United States
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
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Sold between 100 and 1 000 dollars
  • United States
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
  • Australia
  • Beta Tester
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Sold between 10 000 and 50 000 dollars
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