3 posts
  • Has sold $1,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Made it to the Authors' Hall of Fame
  • Located in Brazil
+2 more
FlashCube says

Maybe I’ve done nothing new, but I’ve came up with this code to find out the stage inside a class, I’ve tried with a few MovieClips and worked fine, but I’m still not sure, can someone try it out?

The code is for getting the instance of the main timeline using a ‘target’ movieClip (The class therefore doesn’t need to extend MovieClip class).

    var mainStage:DisplayObject = target.parent;
    var trashParent:DisplayObject;

    for ( trashParent = target.parent ; !(trashParent is Stage) ; trashParent = trashParent.parent )
         {mainStage = trashParent.parent;}

    trace(mainStage.width , mainStage.height); //testing purposes

(Change target to the instance name of the MovieClip).

4140 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 1+ members
  • Has sold $5,000+ on Envato Market
  • Located in Brazil
+3 more
tsafi says

Ola .
That’s more suitable for timeline coding when you keep everything on the global, you should try avoiding using so many parent and control your syntax code with better private variable syntax, but hey it’s a matter of preference whats work for you .

Also when you posting stuff about the holy coding language do it on AD cos` the mod` probably will throw this back to AD forum any way .

110 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 100+ items on Envato Market
+3 more
Devarai says

Why don’t you add an “ADDED_TO_STAGE” event ? When this is triggered you have it through “this.stage”.

887 posts
  • Pulled off some great moustache to raise money or awareness for Movember Australia
  • Made it to the Authors' Hall of Fame
  • Has sold $40,000+ on Envato Market
  • Has been part of the Envato Community for over 5 years
+6 more
MoeHaydar says

The example below assumes you are using Main.as as your main/driver class

//create a new private and static variable
private static var _instance:Main;
//constructor
public function Main(){
         _instance=this;
}
//get function that returns an instance of main
public static function get instance():Main {
        return _instance;
}

Inside any class, you access the stage by using:

Main.instance.stage
3 posts
  • Has sold $1,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Made it to the Authors' Hall of Fame
  • Located in Brazil
+2 more
FlashCube says
SimplyDo said
The example below assumes you are using Main.as as your main/driver class
//create a new private and static variable
private static var _instance:Main;
//constructor
public function Main(){
         _instance=this;
}
//get function that returns an instance of main
public static function get instance():Main {
        return _instance;
}

Inside any class, you access the stage by using:

Main.instance.stage

Do I need to extend MovieClip Class to get the instance?

3 posts
  • Has sold $1,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Made it to the Authors' Hall of Fame
  • Located in Brazil
+2 more
FlashCube says
tsafi said
That’s more suitable for timeline coding when you keep everything on the global, you should try avoiding using so many parent and control your syntax code with better private variable syntax, but hey it’s a matter of preference whats work for you .

Thanks for the tip, I’m new to ActionScript and I’m just starting with OOP concept, thanks anyway . . . :)

Devarai said
Why don’t you add an “ADDED_TO_STAGE” event ? When this is triggered you have it through “this.stage”.

At least the few times I tried the ADDED _TO_STAGE, it seemed not work as expected, and I wanted more control knowing what the root / stage was.

tsafi said
Also when you posting stuff about the holy coding language do it on AD cos` the mod` probably will throw this back to AD forum any way .

Sorry, I’ve seen an AS3 topic and I though this would be the right place . . . :D

887 posts
  • Pulled off some great moustache to raise money or awareness for Movember Australia
  • Made it to the Authors' Hall of Fame
  • Has sold $40,000+ on Envato Market
  • Has been part of the Envato Community for over 5 years
+6 more
MoeHaydar says
FlashCube said
SimplyDo said
The example below assumes you are using Main.as as your main/driver class
//create a new private and static variable
private static var _instance:Main;
//constructor
public function Main(){
         _instance=this;
}
//get function that returns an instance of main
public static function get instance():Main {
        return _instance;
}

Inside any class, you access the stage by using:

Main.instance.stage
Do I need to extend MovieClip Class to get the instance?

In your driver/main class yes

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