Note that there are some explanatory texts on larger screens.

plurals
  1. POActionscript 3.0 adding and removing children
    primarykey
    data
    text
    <p>So basically I've got a MovieClip called Jug and when the egg is clicked and dragged to the Jug I want it to disappear and then re-add itself in the place it first started. Aswell as this I want a variable to be added by 1 in value.</p> <p>I have tried fiddling around with this for a while now and I can't figure it out since when I remove child it gets errors. Here's the code:</p> <pre><code>var eggClickOffset:Point = null; var egg:Egg = new Egg(); egg.x = 290; egg.y = 330; addChild(egg); var eggAmount:TextField = new TextField(); eggAmount.defaultTextFormat = textFormat; eggAmount.x = 250; eggAmount.y = 60; eggAmount.height = 18; eggAmount.width = 100; eggAmount.border = true; eggAmount.text = "Incorrect Amount"; eggAmount.background = true; eggAmount.backgroundColor = 0xff0000; stage.focus = eggAmount; addChild(eggAmount); var eggs:int; eggs = 0; //Egg Event listeners: egg.addEventListener(Event.ENTER_FRAME, eggAmountCounter); egg.addEventListener(MouseEvent.MOUSE_DOWN, startEggDrag); egg.addEventListener(MouseEvent.MOUSE_UP, stopEggDrag); egg.addEventListener(Event.ENTER_FRAME, dragEgg); egg.addEventListener(Event.ENTER_FRAME, checkEggCollision); //starting egg drag: function startEggDrag(event:MouseEvent):void { eggClickOffset = new Point(event.localX,event.localY); } //Stopping the egg drag: function stopEggDrag(event:MouseEvent):void { eggClickOffset = null; } //Egg Dragging: function dragEgg(event:Event):void { if (eggClickOffset != null) {// must be dragging egg.x = mouseX - eggClickOffset.x; egg.y = mouseY - eggClickOffset.y; } } //When egg hits jug: function checkEggCollision(event:Event):void { if (jug.hitTestObject(egg)) { eggs + 1; egg.removeEventListener(MouseEvent.MOUSE_DOWN, startEggDrag); egg.removeEventListener(Event.ENTER_FRAME, dragEgg); removeChild(egg); addChild(egg); egg.x = 300; egg.y = 300; } } //How many eggs: function eggAmountCounter(event:Event):void { if(eggs == 3){ eggAmount.text = "Corrent Amount"; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload