Need help controlling image loop (Enter Frame) - Oi.
I have a series of images coming coming in from XML (it's actually a front & back card flip effect).
I use a for loop and add an ENTER_FRAME listener to each front/back (or image). I then change the X loc of each target...
Code:
public function formatXMLContent():void {
for (var i:uint = 0; i < tourID.length(); i++) {
card = new FlipImage(frontView[i], backView[i]);
card.name = "card"+i;
card.x = -i * 260;
card.y = 0;
card.fLen = 300;
card.turnSpeed = 36;
card.addEventListener(Event.ENTER_FRAME, moveRight);
this.addChild(card);
cardArr.push(card);
setChildIndex(card, 1);
}
cardAddReset = cardArr.length * 198.75;
// trace(cardAddReset);
// trace(cardAddReset);
}
public function moveRight(e:Event):void {
e.target.x += 10;
if (e.target.x > 850) e.target.x = -cardAddReset;
}
This loops perfectly from stage left to stage right endlessly. That's great. However, I need two buttons, forward & back to control the loop. Not ENTER_FRAME.
Code:
mcArrowRight.addEventListener(MouseEvent.MOUSE_DOWN, scrollRight);
mcArrowLeft.addEventListener(MouseEvent.MOUSE_DOWN, scrollLeft);
In the loop above I add each card to a cardArr Array. Thinking I could manipulate the whole array but it completely fudges my loop. The first sequence rolls through nice but those after that look bent.
Code:
public function scrollRight(e:Event):void {
for (var i:uint = 0; i < cardArr.length; i++) {
cardArr[i].x += 10;
if (cardArr[i].x > 850) cardArr[i].x = -cardAddReset;
}
}
I guess this wouldn't have the same affect as the first combo -- that is this must not control the individual items in the array the same as using e.target from the ENTER_FRAME addEventListener itself.