3 posts
  • Sold between 1 000 and 5 000 dollars
  • Brazil
  • Exclusive Author
  • Has been a member for 3-4 years
  • Bought between 10 and 49 items
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
  • Bought between 1 and 9 items
  • Brazil
  • Exclusive Author
  • Has been a member for 6-7 years
  • Referred between 1 and 9 users
  • Sold between 5 000 and 10 000 dollars
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
  • Bought between 100 and 499 items
  • Exclusive Author
  • Germany
  • Has been a member for 4-5 years
  • Referred between 10 and 49 users
  • Sold between 10 000 and 50 000 dollars
Devarai says

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

848 posts
  • Referred between 1 and 9 users
  • Has been a member for 5-6 years
  • Interviewed on the Envato Notes blog
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Lebanon
  • Exclusive Author
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
  • Sold between 1 000 and 5 000 dollars
  • Brazil
  • Exclusive Author
  • Has been a member for 3-4 years
  • Bought between 10 and 49 items
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
  • Sold between 1 000 and 5 000 dollars
  • Brazil
  • Exclusive Author
  • Has been a member for 3-4 years
  • Bought between 10 and 49 items
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

848 posts
  • Referred between 1 and 9 users
  • Has been a member for 5-6 years
  • Interviewed on the Envato Notes blog
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Lebanon
  • Exclusive Author
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