152 posts
  • 6 Years of Membership
  • Author Level 2
  • Collector Level 1
  • Exclusive Author
+2 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
  • 7 Years of Membership
  • Affiliate Level 2
  • Author Level 2
  • Beta Tester
+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
  • 6 Years of Membership
  • Author Level 2
  • Collector Level 1
  • Exclusive Author
+2 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
  • 6 Years of Membership
  • Author Level 2
  • Collector Level 1
  • Exclusive Author
+2 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
  • 6 Years of Membership
  • Author Level 2
  • Collector Level 1
  • Exclusive Author
+2 more
new
says

sorry for dowble post

99 posts
  • 7 Years of Membership
  • Affiliate Level 1
  • Author Level 3
  • Collector Level 2
+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
  • 6 Years of Membership
  • Author Level 2
  • Collector Level 1
  • Exclusive Author
+2 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
  • 6 Years of Membership
  • Author Level 2
  • Collector Level 1
  • Exclusive Author
+2 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
  • 6 Years of Membership
  • Australia
  • Author Level 5
  • Beta Tester
+4 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
  • 6 Years of Membership
  • Australia
  • Author Level 5
  • Beta Tester
+4 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.

by
by
by
by
by
by