Skip to main content
hiPiwoly
Participating Frequently
April 25, 2013
Answered

How to go to a random frame and stop ?

  • April 25, 2013
  • 1 reply
  • 1525 views

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

This topic has been closed for replies.
Correct answer moccamaximum

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)

....


1 reply

moccamaximumCorrect answer
Inspiring
April 25, 2013

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)

....


hiPiwoly
hiPiwolyAuthor
Participating Frequently
April 25, 2013

Oh God, thank you ! You're brilliant !

Thank you very very much. I spent several hours trying to find this out.