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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Aneesh ChopraCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.