PDA

View Full Version : Flash actionscript.. start on random frame.


MadTommy
09-03-09, 18:21
Hi lads, not sure if this is a long shot but.. i need some help with some Flash coding. Anyone know actionscript?? :eek:

The frontpage image that changes is not working as i'd like...I want the movie to start at a different/random keyframe every time the movie, i.e web-page is loaded.

I've tried a number of different options, to no avail, yet. I'm an actionscript novice..


I tried setting an array with the keyframes i wanted...

function getFrame() {
//Store frame numbers
var frameArray:Array = [2, 464, 866, 1266, 1667, 2065, 2465, 2865];
//Function to generate random number between two numbers
function getRandom(number1:Number, number2:Number) {
return Math.floor(Math.round(Math.random()*(number1-number2)))+number2;
}
//Get new random number
var rNum:Number = getRandom(0, frameArray.length);
this.gotoAndPlay(frameArray[rNum]);
}
getFrame();

I tried labeling frames and using them..(blue, red etc)

keyFrameLabels = [alpha, bravo, charlie, delta, echo, fox, golf, hotel];
gotoAndPlay(keyFrameLabels[Math.floor(Math.random() * keyFrameLabels.length)]);




Help....:rolleyes:

cyberzomby
09-03-09, 19:40
I might be on the same knowledge level as you. Did a little searching around and found these:

http://board.flashkit.com/board/showthread.php?t=623203

http://board.flashkit.com/board/archive/index.php/t-671696.html

https://flashmove.com/board/showthread.php?t=23303
(this one shows potential)





It is possible :) Now its hoping that they explain it to a level where you can pull it off. (thats usually the trouble I have with tutorials)
I looked in to them a little bit. Did not have the time to check them good though.

MadTommy
09-03-09, 20:24
cheers mate.. none of them quite work for me.. yet.

I have tried these perviously.. i need to sit down and work it out. I know it possible.. i've got a mate who is away who should be able to set me straight next week.

Thought i'd ask anyway. :)

cyberzomby
09-03-09, 20:59
yea. If not than I got a guy who can help you out as well. Hes like a flashking in our class :P

So do you want the movie to display the frames he skips btw? Or just start from a random frame?

MadTommy
10-03-09, 01:53
couldn't sleep... fixed the code :D

stop();
addEventListener('enterFrame',onEnter);
visible = false;
function onEnter(evt){
if(loaderInfo.bytesLoaded == loaderInfo.bytesTotal){
visible = true;
gotoAndPlay(int(Math.random()*totalFrames)+1);
removeEventListener('enterFrame',onEnter);
}
}

Doesn't use keyframes.. but it'll do.

cyberzomby
10-03-09, 07:55
Naice! I wont bother my classmate with easy coding ;) Good that you made it work man.