Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 06-26-2007, 09:26 PM   #1
Djjinn
Registered User
 
Join Date: Dec 2005
Posts: 20
Default Finding What is in a Movieclip

in as2 you could do something like
Code:
var mc:MovieClip = new MovieClip();
mc.attachMovie("new.swf","mc",0);

for(var x in mc)
    trace(x + ": " + mc[x]);
and that would get you all the contents of a movieclip (properties, objects, and whatever)..

but that lil bit of code doesn't do anything for me in as3? anyone know how i can find what movieclips are on the "stage" of the imported movieclip:

I'm using

Code:
var Main:MovieClip = new MovieClip();

btnLoad.addEventListener(MouseEvent.MOUSE_UP, loadSwf);
btnParse.addEventListener(MouseEvent.MOUSE_UP, parseMC);

function loadSwf(e:MouseEvent)
{
	var req:URLRequest = new URLRequest("navBase.swf");
	var ldr:Loader = new Loader();
	ldr.addEventListener(Event.INIT, loadHandler);
	ldr.load(req);
	addChild(ldr);
}

function loadHandler(e:Event)
{	
	Main = e.target.content;	
}

function parseMC(e:MouseEvent)
{
	// this was an attempt of using the movieclip as a DisplayObjectContainer 
	// since it appears to extend that class but it returns 0 children even 
	// though i see some on the stage
	trace(Main.numChildren);
}
Djjinn is offline   Reply With Quote
Old 06-27-2007, 02:16 AM   #2
Sleeve
Corrupted Whitespace
 
Join Date: May 2006
Location: Seattle, WA
Posts: 489
Default

Hi-

The for...in loop will only propagate properties of a dynamic class.

That old AS2.0 code will work for MovieClips because the MovieClip class is a dynamic class; except it will not return child objects because they are referenced in the DisplayObjectContainer class which is not dynamic.

Also, a display object's "stage" property refers to the Stage of the display object which is also not a dynamic class therefore you cannot use a for...in loop to iterate its properties.

The closest thing you can get to the old AS2.0 functionality on a non-dynamic class is describeType(). Although it still will not return objects or references to objects that may exist in the display list.

You can alternatively write a function that traverses the displaylistcontainer and returns an array of objects within the display list.
ActionScript Code:
protected function traverseDisplayList(dObj : DisplayObjectContainer) : Array {     var a : Array = [];     for (var i : int = 0; i < dObj.numChildren; i++)     {         if (dObj.getChildAt(i) is MovieClip) // or whatever...         {             a.push(dObj.getChildAt(i));         }     }     return a; }
__________________
Some people smoke, some drink...I code Actionscript
Sleeve is offline   Reply With Quote
Old 06-27-2007, 12:43 PM   #3
Djjinn
Registered User
 
Join Date: Dec 2005
Posts: 20
Default

well it appears I made a few mistakes.

First the Event.COMPLETE isn't called by the loader, but actually called by the Loader.contentLoaderInfo.

Code:
var Main; // yes its an untyped object... I'll explain later
var ldr:Loader = new Loader();

btnLoad.addEventListener(MouseEvent.MOUSE_UP, loadSWF);

function loadSWF(e:MouseEvent){

    if(ldr.content != null)
                removeChild(ldr);

    var req:URLRequest = new URLRequest("navBase.swf");
    ldr = new Loader();


    ldr.contentLoaderInfo.addEventListener(Event.COMPLETE,COMPLETEHandler);
     ldr.load(req);
     addChild(ldr);         
}

function COMPLETEHandler(e:Event) {
      Main = ldr.content;
      
      for(var i = 0; i < Main.numChildren; ++i)
      {
             trace(Main.getChildAt(i));
       }
}
ok here we go:
To get all of the objects within the loaded Movieclip i had to wait for the movie clip to finish loading ... yeah makes perfect sense now, but I started this project in FLEX, and there I could assign a name to the container at INIT of the SwfLoader..

Ok after you have got the completed swf all that is left is to save the ldr.content, which was a little odd and explained below.

ldr.content returns [Object MainTimeline], well i can't find anything that is related to what kind of object this is... This is why I have to save to anUntyped variable type. If anyone knows what object type this is that would be great... i hate seeing an Untyped global variable

thanks
Djjinn is offline   Reply With Quote
Old 06-27-2007, 02:17 PM   #4
Sleeve
Corrupted Whitespace
 
Join Date: May 2006
Location: Seattle, WA
Posts: 489
Default

ActionScript Code:
trace(this is DisplayObjectContainer);//true trace(this is DisplayObject)//true trace(this is Sprite)//true trace(this is MovieClip)//true trace(this is InteractiveObject)//true

I suppose you can take your pick with one of these...
__________________
Some people smoke, some drink...I code Actionscript
Sleeve is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Buttons in movieclip don't work FlashAlison ActionScript 2.0 11 03-07-2007 11:46 PM
Buttons in movieclip don't work (Ready to beat pc with a frying pan!) FlashAlison Flash 8 General Questions 15 06-22-2006 02:57 PM
The second time a movieclip is attaced it shal just play from the beginning fiona ActionScript 2.0 0 04-17-2006 04:46 PM
Button on a MovieClip? Talon ActionScript 2.0 2 04-26-2004 03:51 PM
Finding the MovieClip name the Mouse is over Slowburn ActionScript 1.0 (and below) 2 11-22-2003 01:46 AM


All times are GMT. The time now is 08:32 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.