Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

error #2025: addChaild and removeChild

Guest
Sep 08, 2013 Sep 08, 2013

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

TOPICS
ActionScript
622
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 08, 2013 Sep 08, 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.

...
Translate
Community Expert ,
Sep 08, 2013 Sep 08, 2013
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines