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 7 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?

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); }

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
Hey, thats almost the same problem I had when you and tinman helped me. Huh huh funny.

Yep, pretty much a common speedbump in the learning curve.

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by