Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to go to a random frame and stop ?

New Here ,
Apr 25, 2013 Apr 25, 2013

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

TOPICS
ActionScript
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guru , Apr 25, 2013 Apr 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)

....


Translate
Guru ,
Apr 25, 2013 Apr 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)

....


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 25, 2013 Apr 25, 2013
LATEST

Oh God, thank you ! You're brilliant !

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines