Reputation: 92
I thought i should be smart and made/copy a removeAllChildren function which worked nice. But now I get "Error #2069: The Loader class does not implement this method" If i understanded it correctly so is it because I have a loaded picture in a Sprite. (But I'm almost sure it worked with the same type of pictures when I build the function as now.) I cant figure out how to go around it. Think catch error should work somehow, but havn't succeded with it. Or is something else I doing wrong?
This is the picture in R class
public static var picture:Class;
[Embed(source="picture.png")]
The child:
private var bg:Sprite=new R.picture;
canvas.addchild(bg);
My removechildrenfunction:
public static function removeAllChildren(doc:*):void {
while(doc.numChildren){
if (doc.getChildAt(0) is DisplayObjectContainer)
removeAllChildren(doc.getChildAt(0));
doc.removeChildAt(0);
}
}
Upvotes: 0
Views: 198
Reputation: 8793
you are sending removeAllChildren function parameter typed as Loader
from Loader Reference
The Loader class overrides the following methods that it inherits, because a Loader object can only have one child display object—the display object that it loads. Calling the following methods throws an exception: addChild(), addChildAt(), removeChild(), removeChildAt(), and setChildIndex(). To remove a loaded display object, you must remove the Loader object from its parent DisplayObjectContainer child array.
public static function removeAllChildren(doc:*):void {
if(doc is Loader && doc.parent != null)
{
doc.parent.removeChild(doc);
return;
}
while(doc.numChildren){
if (doc.getChildAt(0) is DisplayObjectContainer){
removeAllChildren(doc.getChildAt(0));
}
doc.removeChildAt(0);
}
}
Upvotes: 1