Actionscript 3 Class Architecture

Hi,

I am writing an as3 program where i have a class called Main, which is the document class. Within this class i have created an Object of another class 'XYZ' .


What method should i adopt to access the movieclips etc on stage (which are children of Main class, since it is document class) from inside of XYZ class?

Also when i want to add something to the stage using addChild in XYZ class, how do i do it ?

young_buddhaAsked:
Who is Participating?
 
Aneesh ChopraConnect With a Mentor Commented:
from object of class "XYZ" you can access document class  using 'parent' properly,
just make sure XYZ class should expend "Sprite'' or "MovieClip"

sample code :

trace(MovieClip(this.parent));  //  this will return the reference of document class
0
 
Aneesh ChopraCommented:
1)
You can access the movieClips on stage by simply using its instance name
"this" keyword in document class refers to the stage.

example:
// both will refer to the instnace of a movieClip on stage which has the instance name "myMovie"
this.myMovie;  
or  
myMovie;  

another approach is by using "getChildByName()" method

example:
this.getChildByName("myMovie");  // this will also return the reference to the movieclip with instance name "myMovie"

2)
you can simply add movieClip using :

this.addChild("<MovieClipInstance>");
or
addChild("<MovieClipInstance>");
0
 
young_buddhaAuthor Commented:
Actually what i was asking is, that how do i do the same from an OBJECT OF CLASS 'XYZ', which i have created inside the Document class?

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.