Actionscript 3  Class Architecture

Posted on 2008-11-13
Last Modified: 2013-11-11

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 ?

Question by:young_buddha
    LVL 34

    Expert Comment

    by:Aneesh Chopra
    You can access the movieClips on stage by simply using its instance name
    "this" keyword in document class refers to the stage.

    // both will refer to the instnace of a movieClip on stage which has the instance name "myMovie"

    another approach is by using "getChildByName()" method

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

    you can simply add movieClip using :


    Author Comment

    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?

    LVL 34

    Accepted Solution

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
    I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
    In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
    This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now