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).
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 .
Why don’t you add an “ADDED_TO_STAGE” event ? When this is triggered you have it through “this.stage”.
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
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?
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 . . . 
FlashCube said
SimplyDo saidDo I need to extend MovieClip Class to get the instance?
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
In your driver/main class yes
