Skip to main content
September 8, 2013
Answered

error #2025: addChaild and removeChild

  • September 8, 2013
  • 1 reply
  • 673 views

hello all

I have the app but I got a problem

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

at flash.display :: DisplayObjectContainer / removeChild ()

at xxxxx_fla :: MainTimeline / hitPoint ()

my code

import flash.events.Event;

import flash.events.MouseEvent;

var pencilta:Shape = new Shape();

var activeColor:uint = 0x000000;

var aaa:a = new a();

aaa.x = 0;

aaa.y = 0;

addChild(aaa);

var bbb:c1 = new c1();

bbb.x = 308;

bbb.y = 108;

addChild(bbb);

var ccc:c2 =new c2();

ccc.x = 265;

ccc.y = 175;

addChild(ccc);

var ddd:c2 = new c2();

ddd.x = 235;

ddd.y = 260;

var eee:c2 =new c2();

eee.x = 200;

eee.y = 355;

bbb.addEventListener(MouseEvent.MOUSE_DOWN, hta1drag);

bbb.addEventListener(MouseEvent.MOUSE_UP, hta1drop);

bbb.addEventListener(Event.ENTER_FRAME, hitPoint);

function drawingta()

{

          addChild(pencilta);

          pencilta.graphics.lineStyle(10, activeColor);

}

function drawPencilta(e:MouseEvent):void

{

          pencilta.graphics.lineTo(bbb.x, bbb.y);

          e.updateAfterEvent();

}

function hta1drag(e:MouseEvent):void

{

          e.target.startDrag();

          pencilta.graphics.moveTo(bbb.x, bbb.y);

          stage.addEventListener(MouseEvent.MOUSE_MOVE, drawPencilta);

          drawingta();

}

function hta1drop(e:MouseEvent):void

{

          stopDrag();

          stage.removeEventListener(MouseEvent.MOUSE_MOVE, drawPencilta);

}

function hitPoint(e:Event)

{

          if(bbb.hitTestPoint(ccc.x,ccc.y, true))

          {

                    removeChild(ccc);

                    addChild(ddd);

          }

          else if (bbb.hitTestPoint(ddd.x,ddd.y,true))

          {

                    removeChild(ddd);

                    addChild(eee);

          }

          else

          {

                    trace ('mbuh lah');

          }

}

thank's

This topic has been closed for replies.
Correct answer kglad

use:

import flash.events.Event;

import flash.events.MouseEvent;

var pencilta:Shape = new Shape();

var activeColor:uint = 0x000000;

var aaa:a = new a();

aaa.x = 0;

aaa.y = 0;

addChild(aaa);

var bbb:c1 = new c1();

bbb.x = 308;

bbb.y = 108;

addChild(bbb);

var ccc:c2 =new c2();

ccc.x = 265;

ccc.y = 175;

addChild(ccc);

var ddd:c2 = new c2();

ddd.x = 235;

ddd.y = 260;

var eee:c2 =new c2();

eee.x = 200;

eee.y = 355;

bbb.addEventListener(MouseEvent.MOUSE_DOWN, hta1drag);

bbb.addEventListener(MouseEvent.MOUSE_UP, hta1drop);

bbb.addEventListener(Event.ENTER_FRAME, hitPoint);

function drawingta()

{

          addChild(pencilta);

          pencilta.graphics.lineStyle(10, activeColor);

}

function drawPencilta(e:MouseEvent):void

{

          pencilta.graphics.lineTo(bbb.x, bbb.y);

          e.updateAfterEvent();

}

function hta1drag(e:MouseEvent):void

{

          e.target.startDrag();

          pencilta.graphics.moveTo(bbb.x, bbb.y);

          stage.addEventListener(MouseEvent.MOUSE_MOVE, drawPencilta);

          drawingta();

}

function hta1drop(e:MouseEvent):void

{

          stopDrag();

          stage.removeEventListener(MouseEvent.MOUSE_MOVE, drawPencilta);

}

function hitPoint(e:Event)

{

          if(bbb.hitTestPoint(ccc.x,ccc.y, true))

          {

if(ccc.stage){

                    ccc.parent.removeChild(ccc);

// ccc=null; ??

}

                    addChild(ddd);

          }

          else if (bbb.hitTestPoint(ddd.x,ddd.y,true))

          {

if(ddd.stage){

                    ddd.parent.removeChild(ddd);

// ddd = null; ??

}

                    addChild(eee);

          }

          else

          {

                    trace ('mbuh lah');

          }

}

thank's

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
September 8, 2013

use:

import flash.events.Event;

import flash.events.MouseEvent;

var pencilta:Shape = new Shape();

var activeColor:uint = 0x000000;

var aaa:a = new a();

aaa.x = 0;

aaa.y = 0;

addChild(aaa);

var bbb:c1 = new c1();

bbb.x = 308;

bbb.y = 108;

addChild(bbb);

var ccc:c2 =new c2();

ccc.x = 265;

ccc.y = 175;

addChild(ccc);

var ddd:c2 = new c2();

ddd.x = 235;

ddd.y = 260;

var eee:c2 =new c2();

eee.x = 200;

eee.y = 355;

bbb.addEventListener(MouseEvent.MOUSE_DOWN, hta1drag);

bbb.addEventListener(MouseEvent.MOUSE_UP, hta1drop);

bbb.addEventListener(Event.ENTER_FRAME, hitPoint);

function drawingta()

{

          addChild(pencilta);

          pencilta.graphics.lineStyle(10, activeColor);

}

function drawPencilta(e:MouseEvent):void

{

          pencilta.graphics.lineTo(bbb.x, bbb.y);

          e.updateAfterEvent();

}

function hta1drag(e:MouseEvent):void

{

          e.target.startDrag();

          pencilta.graphics.moveTo(bbb.x, bbb.y);

          stage.addEventListener(MouseEvent.MOUSE_MOVE, drawPencilta);

          drawingta();

}

function hta1drop(e:MouseEvent):void

{

          stopDrag();

          stage.removeEventListener(MouseEvent.MOUSE_MOVE, drawPencilta);

}

function hitPoint(e:Event)

{

          if(bbb.hitTestPoint(ccc.x,ccc.y, true))

          {

if(ccc.stage){

                    ccc.parent.removeChild(ccc);

// ccc=null; ??

}

                    addChild(ddd);

          }

          else if (bbb.hitTestPoint(ddd.x,ddd.y,true))

          {

if(ddd.stage){

                    ddd.parent.removeChild(ddd);

// ddd = null; ??

}

                    addChild(eee);

          }

          else

          {

                    trace ('mbuh lah');

          }

}

thank's