Search code examples
actionscript-3flashactionscriptgame-physics

falling bottle not falling


I want to create a game of falling objects. In this case I have only one bottle and i want it to fall but it's not working. As you can see in the picture, the bottle starts to distort, it's not falling. Thanks!

   function bottleCreate(e:Event):void {

    var bottleNew:MovieClip;

    bottleNew = newBottle();
        bottleNew.x = 100;
        bottleNew.y=0;

    addChild(bottleNew);
bottle.addEventListener(Event.ENTER_FRAME, bottleMove);
}

function bottleMove(e:Event):void {
        e.target.y ++;          
}

stage.addEventListener(Event.ENTER_FRAME, bottleCreate);

enter image description here


Solution

  • You should remove the event listener for bottleCreate function, by adding

    stage.removeEventListener(Event.ENTER_FRAME, bottleCreate);

    to your bottleCreate function.

    Or

    Call bottleCreate function once , instead of using

    stage.addEventListener(Event.ENTER_FRAME, bottleCreate);