Skip to main content
gulhangulez
Participating Frequently
April 20, 2010
Answered

ArgumentError: Error #2025 - I can not removeChild?

  • April 20, 2010
  • 1 reply
  • 666 views
function urunlergelsin (e:MouseEvent):void {
    var urunlermenum:urunlermenu = new urunlermenu();
    bg.solurunmenusu.addChild(urunlermenum); // Added new one
    var geridonbuton:geridon = new geridon();
    bg.geridonus_mc.addChild(geridonbuton);
    bg.geridonus_mc.addEventListener(MouseEvent.MOUSE_DOWN, geridon_f);
    }

function geridon_f(e:MouseEvent):void {
    bg.urunbtn.removeEventListener(MouseEvent.MOUSE_DOWN, urunlergelsin);
    bg.geridonus_mc.removeEventListener(MouseEvent.MOUSE_DOWN, geridon_f);
    var urunlermenum:urunlermenu = new urunlermenu();

    bg.solurunmenusu.removeChild(urunlermenum); // But when i try ro remove it doesnt work
    }

Hello,

When i try to removeChild i am getting this error message, How can i solve this problem?

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.

     at flash.display::DisplayObjectContainer/removeChild()
     at avas_fla::MainTimeline/geridon_f()

This topic has been closed for replies.
Correct answer Ned Murphy

Your problem likely lies in declaring the object inside a function.  It will only have scope within that function when you do that.  I see where you create a new instance of the object in the function where I assume you are trying to remove the first one... the second one is the only one seen at that point, and it has not been added.  Try the following:

var urunlermenum:urunlermenu; // declare it outside any function

function urunlergelsin (e:MouseEvent):void {
    urunlermenum = new urunlermenu();
    bg.solurunmenusu.addChild(urunlermenum); // Added new one
    var geridonbuton:geridon = new geridon();
    bg.geridonus_mc.addChild(geridonbuton);
    bg.geridonus_mc.addEventListener(MouseEvent.MOUSE_DOWN, geridon_f);
    }

function geridon_f(e:MouseEvent):void {
    bg.urunbtn.removeEventListener(MouseEvent.MOUSE_DOWN, urunlergelsin);
    bg.geridonus_mc.removeEventListener(MouseEvent.MOUSE_DOWN, geridon_f);

    var urunlermenum:urunlermenu = new urunlermenu();  // remove this
    bg.solurunmenusu.removeChild(urunlermenum);

}

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
April 20, 2010

Your problem likely lies in declaring the object inside a function.  It will only have scope within that function when you do that.  I see where you create a new instance of the object in the function where I assume you are trying to remove the first one... the second one is the only one seen at that point, and it has not been added.  Try the following:

var urunlermenum:urunlermenu; // declare it outside any function

function urunlergelsin (e:MouseEvent):void {
    urunlermenum = new urunlermenu();
    bg.solurunmenusu.addChild(urunlermenum); // Added new one
    var geridonbuton:geridon = new geridon();
    bg.geridonus_mc.addChild(geridonbuton);
    bg.geridonus_mc.addEventListener(MouseEvent.MOUSE_DOWN, geridon_f);
    }

function geridon_f(e:MouseEvent):void {
    bg.urunbtn.removeEventListener(MouseEvent.MOUSE_DOWN, urunlergelsin);
    bg.geridonus_mc.removeEventListener(MouseEvent.MOUSE_DOWN, geridon_f);

    var urunlermenum:urunlermenu = new urunlermenu();  // remove this
    bg.solurunmenusu.removeChild(urunlermenum);

}

gulhangulez
Participating Frequently
April 20, 2010

Thanks so much. You saved my life..

I have a one more question about that.. How can i access to this added child?

When i try

urunlermenum.name="mcinstance";

bg.solurunmenusu.mcinstance.gotoAndPlay(2); // doesnt work

How can i use addChild and gotoAndPlay together?

Ned Murphy
Legend
April 20, 2010

Actually, you don't need all that. since the object can be directly targeted...

urunlermenum.gotoAndPlay(2);

The name of an object is just a property, not an instance name, and it is just a string value.  When you use the name of an object you need to use getChildByName().

Please mark this posting as answered if you can.