3 posts
  • Author Level 3
  • Collector Level 2
  • Weekly Top Seller
  • Featured Author
+3 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
  • 7 Years of Membership
  • Affiliate Level 1
  • Author Level 4
  • Brazil
+5 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
  • Top Monthly Author
  • Weekly Top Seller
  • 5 Years of Membership
  • Author Level 5
+5 more
Devarai
says

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

891 posts Thinking Big
  • Trendsetter
  • Weekly Top Seller
  • Elite Author
  • Author Level 7
+8 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
  • Author Level 3
  • Collector Level 2
  • Weekly Top Seller
  • Featured Author
+3 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
  • Author Level 3
  • Collector Level 2
  • Weekly Top Seller
  • Featured Author
+3 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

891 posts Thinking Big
  • Trendsetter
  • Weekly Top Seller
  • Elite Author
  • Author Level 7
+8 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

by
by
by
by
by
by