-
Question on using a SQL Check in a setup random timeline
I am extremely new to flash, so I hope I can get some help on this? I have a timeline setup to choose a random image every time a button is pressed, which works great BUT sometimes when I hit the button again the SAME image is chosen multiple times in a row before it chooses a different one. Is using a 'SQL Check' (which I have no idea about) the right way to fix that problem? If so how do I write out the code properly? Any help would be great, thanks
This is what I currently have to have it chose a random image:
gotoAndStop(random(15)+2);
bsb
PS: I'm using ActionScript 2
-
.
Hi,
Not sure what your 15 and 2 signify, but this should help you do the right thing, if you can alter it to use your 15,2
It basically selects a random number from the range and if its the same as the last choice it picks another number until its not the same as last selection.
PHP Code:
stop();
var pageAmount:Number = 17;
var nextNumber:Number;
var newNumber:Number;
var previousNumber:Number;
button.onPress = function()
{
nextNumber = Math.floor(Math.random() * pageAmount);
getRandom(nextNumber);
};
function getRandom(arg:Number)
{
if (arg == previousNumber)
{
newNumber = Math.floor(Math.random() * pageAmount);
trace("Same as before, get new number");
getRandom(newNumber);
}
else
{
previousNumber = arg;
trace("New: " + arg);
frameText.text = "Frame: " + String(arg);
gotoAndStop(arg);
return;
}
}
-
thanks for the reply :)
Originally Posted by fruitbeard
Hi,
Not sure what your 15 and 2 signify, but this should help you do the right thing, if you can alter it to use your 15,2
It basically selects a random number from the range and if its the same as the last choice it picks another number until its not the same as last selection.
PHP Code:
stop();
var pageAmount:Number = 17;
var nextNumber:Number;
var newNumber:Number;
var previousNumber:Number;
button.onPress = function()
{
nextNumber = Math.floor(Math.random() * pageAmount);
getRandom(nextNumber);
};
function getRandom(arg:Number)
{
if (arg == previousNumber)
{
newNumber = Math.floor(Math.random() * pageAmount);
trace("Same as before, get new number");
getRandom(newNumber);
}
else
{
previousNumber = arg;
trace("New: " + arg);
frameText.text = "Frame: " + String(arg);
gotoAndStop(arg);
return;
}
}
I'm sorry I guess have mentioned what the 15 & 2 were. For the timeline the 15 is for how many frames are in the timeline and the 2 is where I want the 'random' choice to start when I hit the button, because 'frame 1' has the actionscript telling it to make a random choice.
so for the code you sent me, is there anywhere in it, where I need to exchange information to something in -my- flash program? like when you write out 'number' do i change that with anything, or do I write it out exaacly how you wrote it? Sorry I'm REALLY new to flash, so you have to bare with me.
bsb
-
.
Hi,
here is a file for you to look at, it will help you.
If you are are unable to open it (saved as CS5), then here is some code,
with a button called button on the stage, use this code
PHP Code:
stop();
var endFrame:Number = 17;// create and declare variable var startFrame:Number = 2;// create and declare variable var nextNumber:Number;// create variable only var newNumber:Number;// create variable only var previousNumber:Number;// create variable only
// button code button.onPress = function() { // next frame to go to = nextNumber = Math.floor(Math.random() * (1 + endFrame - startFrame)) + startFrame; // call function getRandom(with next frame to go to number) getRandom(nextNumber); };
// random no repeat last number function function getRandom(arg:Number) { // arg becomes nextNumber from function call // if arg is same as last number called, call another number // else go to that frame number if (arg == previousNumber) { // random number again newNumber = Math.floor(Math.random() * (1 + endFrame - startFrame)) + startFrame; trace("Same as before, get new number"); // try again with new number getRandom(newNumber); } else { // declare this number as previous number previousNumber = arg; trace("New: " + (arg)); // goto frame gotoAndStop(arg); } }
-
Wow! That is exactly what I needed. Works pretty cool. Now I have to figure out how to incorporate it into my flash program I'm working on. I really appreciate your help!
bsb
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|