speed is accumulating
Hi,
I have a simple code.
One item is on stage, and it is moving after clicked. Based on the x value, additional three movieclips are added to the stage. And pushed to an array.
They are all moving with the same speed.
I need control the motion via the first movie clip (the one already on stage, PartSuur).
When it is clicked, the item itself and the items in array should stop.
And they do.
When clicked again, they should start moving again. With the same speed as before.
PartSuur is moving and stopping correctly. But the items in array start to speed up after each stop and move click.
I have tried a few changes in the code, couldn't solve it.
Hope someone has time to review and give me some advice.
Many thanks in advance!
origX = PartSuur.x;
origY = PartSuur.y;
PartSuur.addEventListener(MouseEvent.CLICK, addEnterFrame);
function addEnterFrame(event: MouseEvent): void
{
PartSuur.removeEventListener(MouseEvent.CLICK, addEnterFrame);
PartSuur.addEventListener(Event.ENTER_FRAME, moveDuckBig);
for(var i: uint = 0; i < arrayDuckSmall.length; i++)
{
arrayDuckSmall.addEventListener(Event.ENTER_FRAME, moveDuckSmall);
trace(".EventListener added");
}
PartSuur.addEventListener(MouseEvent.CLICK, stopDucks);
}
function moveDuckBig(event: Event): void
{
PartSuur.x += 0.5;
if(PartSuur.x == origX + 75)
{
addDuck();
}
if(PartSuur.x == origX + 125)
{
addDuck();
}
if(PartSuur.x == origX + 175)
{
addDuck();
}
}
function stopDucks(event: MouseEvent): void
{
PartSuur.removeEventListener(Event.ENTER_FRAME, moveDuckBig);
for(var i: uint = 0; i < arrayDuckSmall.length; i++)
{
arrayDuckSmall.removeEventListener(Event.ENTER_FRAME, moveDuckSmall);
trace(".EventListener removed");
}
PartSuur.addEventListener(MouseEvent.CLICK, addEnterFrame);
}
function addDuck(): void
{
newDuckSmall = new partVaike();
addChild(newDuckSmall);
arrayDuckSmall.push(newDuckSmall);
newDuckSmall.scaleX = 1;
newDuckSmall.scaleY = newDuckSmall.scaleX;
newDuckSmall.x = origX;
newDuckSmall.y = origY;
arrayDuckSmall.addEventListener(Event.ENTER_FRAME, moveDuckSmall);
}
function moveDuckSmall(event: Event): void
{
for(var i: uint = 0; i < arrayDuckSmall.length; i++)
{
arrayDuckSmall.x += 0.5;
}
}
