flashactionscript-3flash-cs4movieclip

Access MovieClip instances that are already on the stage in Document Class?


I have created a game in flash, and due to the nature of the game, I have many movieclips placed on the stage manually in Flash CS4. They are not programmatically added as children to the stage, and so I am having difficulty getting access to them in the document class. So far the only method I have been able to use is to do stage.addChild(active_area); (for example), but there are many movie clips, all very differently named, so this method seems incorrect.

I've discovered that my MovieClips are not children of the stage, but in fact MainTimeline, as when I for loop through stage.getChildAt(i);, only one child, root1, is traced out.

How can I access movieclips that were placed on the stage in the timeline from the document class, without having to manually add them as children to the stage?

[EDIT]


So it looks like my problem wasn't that I couldn't access the MovieClips, it was that I wasn't modifying the MovieClips' values, so I wasn't registering any change in them.

Here is the code after I fixed it:

    function manage_cursor(e:Event):void {
        prevX=currX;
        prevY=currY;
        currX=stage.mouseX;
        currY=stage.mouseY;
        var i:int;

        if (currY > (stage.stageHeight/2)) {

            for (i = 0; i < this.numChildren; i++) {
                if (this.getChildAt(i).name!="active_area" && stage_kelp.y > kelp.min_y_mod) {
                    this.getChildAt(i).y-=1;                    
                }
            }
        }
        if (currY < (stage.stageHeight/2)) {
            for (i = 0; i < this.numChildren; i++) {
                if (this.getChildAt(i).name!="active_area" && this.stage_kelp.y < kelp.max_y_mod) {
                    this.getChildAt(i).y+=1;
                }
            }
        }

    }

The problem before was that I was checking stage.numChildren;, using stage.getChildAt(i), and modifying that child, which was the TimeLine. This gave me the effect of all my other MovieClips on stage being moved, so I was under the assumption their y values were being changed, but they weren't, thus, none of my conditionals were triggering, giving me the illusion that I wasn't getting access to the MovieClips. Changing stage to this, as recommended by package in the answers below, fixed the problem for me.


Solution

  • Try this code in your Document Class:

    trace(this["movieclip_name"]);
    

    this refers to the MainTimeline in your Document Class.