dcsimg
A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: movieclips on the stage?

  1. #1
    infidel! 0vidiu's Avatar
    Join Date
    Mar 2003
    Location
    ROmania
    Posts
    267

    movieclips on the stage?

    Hey guys,

    I have one question: is it possible with AS3 to see the list of the movieclips that are on stage?

    Thanks a lot!

  2. #2
    a.k.a gltovar deadlock32's Avatar
    Join Date
    May 2001
    Location
    Naperville,IL
    Posts
    489
    yes. what you do is click on the movie clip, then goto its properties (bottom of the screen) and give it a name. Then in you document class you can access that movieclip by the name you gave it.

  3. #3
    infidel! 0vidiu's Avatar
    Join Date
    Mar 2003
    Location
    ROmania
    Posts
    267
    the list of movieclips I want to find out the names for are also added from my document class with addChild()

    So no movieclips on the flash stage, just a blank keyframe and a document class.

    Tnx!

  4. #4
    a.k.a gltovar deadlock32's Avatar
    Join Date
    May 2001
    Location
    Naperville,IL
    Posts
    489
    ah whoops ^_^ man.

    you can go about this a few ways.

    one way is:

    PHP Code:
    var names:Array = new Array();
    for(var 
    i:int 0this.numChildreni++)
    {
         
    name.push(this.getChildAt(i).name);

    so the 'this' can be replaces by any display object container, so its good for seeing a list of any child display objects

  5. #5
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    I wrote this yesterday to trace out the name of everything in the dom from any node downward:

    PHP Code:
    function deepTrace(d:DisplayObjectContainerindent:String ''):void{
        var 
    i:int 0;
        var 
    o:*;
        while(
    d.numChildren){
            
    d.getChildAt(i);
            if(
    o is DisplayObjectContainer){
                
    trace(indent o.name);
                
    deepTrace(DisplayObjectContainer(o), indent '\t');
            } else {
                
    trace(indent o.name);
            }
            
    i++;
        }
    }

    //  deepTrace(stage); 
    Depending on what you're trying to do though, it's probably easiest to just open an array and put the objects in there as you add them to the stage - that way you always have a handle on them and you don't have to do a search again later.

  6. #6

  7. #7
    infidel! 0vidiu's Avatar
    Join Date
    Mar 2003
    Location
    ROmania
    Posts
    267
    so.. I tried this and i get that the names array contains "instance1" and "instance2" movieclips. My intention was to have a main mc called bg_mc and inside bg_mc I want to place the square_mc.

    Code:
    package  
    {
    	import flash.display.MovieClip;
    	
    	/**
    	 * ...
    	 * @author infidel - aka Ovidiu Gheorghe
    	 */
    	public class main extends MovieClip
    	{
    		public var bg_mc:bg = new bg();
    		public var square_mc:square = new square();
    		public var names:Array = new Array();
    		
    		public function main() 
    		{
    			addBg();
    			addSquare();
    			
    			//outputTrace();
    			getDisplayList();
    		}
    		
    		private function getDisplayList():void
    		{
    			for(var i:int = 0; i < this.bg_mc.numChildren; i++)
    			{
    				names.push(this.bg_mc.getChildAt(i).name);
    			} 
    			trace(names);
    		}
    		
    		private function addSquare():void
    		{
    			bg_mc.addChild(square_mc);
    		}
    		
    		private function addBg():void
    		{
    			addChild(bg_mc);
    		}
    		
    		private function outputTrace():void
    		{
    			trace(bg_mc.x);
    		}
    		
    	}
    	
    }
    So.. by my logics trace(names); should return square_mc. What I am doing wrong ?

    Tnx a bunch,
    ovidiu

  8. #8
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    square_mc is a variable whose value is a square. That square was never given a name, so it has a default name of instance<something>.

    If you want to see something other than the default when you trace the name property, you're going to have to set that name property to something other than the default.
    Code:
    		public function main() 
    		{
    			addBg();
    			addSquare();
                            square_mc.name = "bob";
    			
    			//outputTrace();
    			getDisplayList();
    		}

  9. #9
    infidel! 0vidiu's Avatar
    Join Date
    Mar 2003
    Location
    ROmania
    Posts
    267
    ok, got it! tnx a lot, really...

    what about the "names" array? how come at trace(names) I see two members inside the array instead of only one?

    tnx a lot!

  10. #10
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    It looks like bg_mc is probably linked to a library item. That item may include children for things such as Shapes to hold graphics, or other things defined inside it.

  11. #11
    infidel! 0vidiu's Avatar
    Join Date
    Mar 2003
    Location
    ROmania
    Posts
    267
    ok.. I still got the error:

    "TypeError: Error #1010: A term is undefined and has no properties.
    at main/addMc()
    at main()"


    Code:
    package  
    {
    	import flash.display.MovieClip;
    	
    	/**
    	 * ...
    	 * @author 
    	 */
    	public class main extends MovieClip
    	{
    		public var bg_mc:bg = new bg();
    		public var square_mc:square = new square();
    		
    		public function main() 
    		{
    			addMc();
    		}
    		
    		private function addMc():void
    		{
    			this.addChild(bg_mc);
    			this.bg_mc.addChild(square_mc);
    			this.bg_mc.square_mc.name = "squareMc";
    			this.bg_mc.squareMc.alpha = 0.7;
    		}
    		
    	}
    	
    }
    what I am doin' wrong?..
    tnx a bunch! Ovidiu

  12. #12
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Adding a child does NOT make a property. That is,
    Code:
    this.addChild(bg_mc);
    does NOT make this.bg_mc. Same with bg_mc.square_mc. Doesn't exist. But that's okay, since you don't need them. You've already got references to bg_mc and square_mc. Just use those.

    Code:
    		private function addMc():void
    		{
    			this.addChild(bg_mc);
    			bg_mc.addChild(square_mc);
    			square_mc.name = "squareMc";
    			squareMc.alpha = 0.7;
    		}

  13. #13
    infidel! 0vidiu's Avatar
    Join Date
    Mar 2003
    Location
    ROmania
    Posts
    267
    Code:
    package  
    {
    	import flash.display.MovieClip;
    	
    	/**
    	 * ...
    	 * @author 
    	 */
    	public class main extends MovieClip
    	{
    		public var bg_mc:bg = new bg();
    		public var square_mc:square = new square();
    		
    		public function main() 
    		{
    			addMc();
    		}
    		
    		private function addMc():void
    		{
    			this.addChild(bg_mc);
    			bg_mc.addChild(square_mc);
    			square_mc.name = "squareMc";
    			squareMc.alpha = 0.7;
    		}
    		
    	}
    	
    }
    this also returns:
    1120: Access of undefined property squareMc.

    tnx,
    Ovidiu

  14. #14
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Oops, yeah. That should be square_mc not squareMc.

    Code:
    		private function addMc():void
    		{
    			this.addChild(bg_mc);
    			bg_mc.addChild(square_mc);
    			square_mc.name = "squareMc";
    			square_mc.alpha = 0.7;
    		}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center