Progaramatically declare Type - Macromedia Flash
This is a discussion on Progaramatically declare Type - Macromedia Flash ; Hi There
consider this recursive function:
private function
setChildrenEditable(DObj isplayObjectContainer,f:Function):void{
for(var i:int=0;i<DObj.numChildren;i++){
if (DObj.getChildAt(i) is IContent){
//do the function
var c:IContent = DObj.getChildAt(i) as IContent;
f(c);
}else if(DObj.getChildAt(i) is DisplayObjectContainer){
//do the recursion
setChildrenEditable(DisplayObjectContainer(DObj.getChildAt(i)),f);
}
}
}
it takes a ...
-
-
Re: Progaramatically declare Type
This should be in the AS3 forum. However, here's something I use that pretty
much does what you need.
import flash.display.*;
import flash.utils.*;
function myCallback(target:Object)
{
trace("myCallback", target);
}
function findChildrenByType(container
isplayObjectContainer,
childType:Object = null,
callback:Function = null,
recursive:Boolean=true
):Array
{
var result:Array = new Array();
if (container==null){return result;}
var typeClass:Class = (childType==null) ? DisplayObject :
childType is Class ? childType as Class : null;
if (typeClass == null)
{
var className:String = flash.utils.getQualifiedClassName(childType);
typeClass = flash.utils.getDefinitionByName(className) as Class;
}
var obj
isplayObject;
for(var i:uint=0; i<container.numChildren; i++)
{
obj = container.getChildAt(i);
if(obj is typeClass)
{
result.push(obj);
if (callback != null)
{
try{callback(obj);} // trap argument count mismatch
catch(e){}
}
}
if (obj is DisplayObjectContainer && recursive)
{
result = result.concat(findChildrenByType(obj as DisplayObjectContainer,
typeClass, callback, recursive));
}
}
return result;
}
trace(findChildrenByType(this, IEventDispatcher, myCallback))
trace(findChildrenByType(this, MovieClip, myCallback))
trace(findChildrenByType(this, TextField, myCallback))
-
Re: Progaramatically declare Type
On 2008-08-08 16:13:17 +0100, "Raymond Basque"
<webforumsuser@macromedia.com> said:
> childType:Object = null,
that is the missing link
thanks I didn't know there was an AS3 group LOL