Copy link to clipboard
Copied
Hello there,
I have a little problem and I can't seem to find any solutions.
What I want is my symbol (="pijl1" in which there are 4 different keyframes on the timeline) to show just one of the keyframes, randomly, and then stop.
(I'm trying to make a game like this http://www.youtube.com/watch?v=sYGJ0TRWdRM in which my symbol would be one of the random arrows)
I made this:
import flash.events.Event;
var pijl1:pijl=new pijl();
pijl1.addEventListener (Event.ENTER_FRAME, randomdirect)
function randomdirect (event:Event) {
var randomFrame:Number=(Math.floor(Math.random()*4)+1);
trace (randomFrame);
pijl1.gotoAndStop (randomFrame);
addChild (pijl1);
pijl1.x=200
pijl1.y=200
}
but it won't stop. It just keeps on going (the output goes crazy).
I don't know if I made myself clear. But if someone understood my problem, could you please help me out ?
Piw
Your enter frame loop constantly "overrides" your gotoAndStop function.
you could simply remove the eventlistener after the gotoAndstop funtion
....
pijl1.gotoAndStop (randomFrame);
pijl1.removeEventListener (Event.ENTER_FRAME, randomdirect)
....
Copy link to clipboard
Copied
Your enter frame loop constantly "overrides" your gotoAndStop function.
you could simply remove the eventlistener after the gotoAndstop funtion
....
pijl1.gotoAndStop (randomFrame);
pijl1.removeEventListener (Event.ENTER_FRAME, randomdirect)
....
Copy link to clipboard
Copied
Oh God, thank you ! You're brilliant !
Thank you very very much. I spent several hours trying to find this out.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now