Monster Racer Rush
Select between 5 monster racers, upgrade your monster skill and win the competition!
4.23 / 5.00 3,881 ViewsBuild and Base
Build most powerful forces, unleash hordes of monster and control your soldiers!
3.93 / 5.00 4,634 Viewsin the menu i want a random tip generator, i've made a movie clip with different movie clips inside that display tips..
but after the animation, i need it to go to a random frame (inside of my movieclip).
does anyone know how i might go about doing this? or what the script is?
AS2 or AS3?
Here I'll do AS3:
function generateRandom(num:int):void
{
tip_mc.gotoAndStop(num);
}
generateRandom(int(Math.random()*tip_mc.totalFrames)); The code that Spysociety posted is incomplete, and as such will not work.
This is because Math.random() returns a variable of type Number that is between 0 and 1. Example being 0.4202162609435618.
You need to use a little math to convert that to a random integer.
The proper way to write Spysociety's code is like so:
function randomInteger(min:int, max:int):int
{
return Math.floor(Math.random() * (1 + (max - min))) + min;
}
function generateRandom(num:int):void
{
tip_mc.gotoAndStop(num);
}
generateRandom(randomInteger(1, 10));
The randomNumber() function used in that context will return a psuedo-random integer between the values 1 and 10.
This will only work in AS3.
His code works fine...maybe you missed the int() that he put in there. Floors the random number * length to get [0,length -1], which works in this language.
:Stupid MATLAB
At 1/25/12 02:27 PM, MSGhero wrote: His code works fine...maybe you missed the int() that he put in there. Floors the random number * length to get [0,length -1], which works in this language.
I didn't miss the int(), I was just not thinking clearly.
I was only thinking in the context of generating a psuedo-random integer of any given range, not specifically an integer with a range always starting at zero.
So I was I wrong about Spysociety's code. It will work in this context.
SORRY GUYS,
i need it in AS2, forgot to mention that :p
The same thing but you change :void to :Void
At 1/25/12 03:21 PM, Spysociety wrote: The same thing but you change :void to :Void
**Error** Symbol=tip_mc, layer=Layer 2, frame=2:Line 2: The class or interface 'int' could not be loaded.
function generateRandom(num:int):Void
would anyone mind making an example for me in flash 8 format please?
I know this mighty would happen. int does exist in AS2 but maybe could not be used in place of a Number.
Just change num:int to num:Number. This will work then.
At 1/25/12 03:51 PM, BabySteps wrote:At 1/25/12 03:21 PM, Spysociety wrote: The same thing but you change :void to :Void**Error** Symbol=tip_mc, layer=Layer 2, frame=2:Line 2: The class or interface 'int' could not be loaded.
function generateRandom(num:int):Void
int isn't available in AS2, you have to use Number instead.
At 1/25/12 03:56 PM, Kirk-Cocaine wrote:At 1/25/12 03:51 PM, BabySteps wrote:int isn't available in AS2, you have to use Number instead.At 1/25/12 03:21 PM, Spysociety wrote: The same thing but you change :void to :Void**Error** Symbol=tip_mc, layer=Layer 2, frame=2:Line 2: The class or interface 'int' could not be loaded.
function generateRandom(num:int):Void
If you write it in AS2:
var num:Number=int(2.1+2.1);
trace(num);
Will output you 4, as it would do in AS3.
At 1/25/12 04:04 PM, Spysociety wrote: If you write it in AS2:
var num:Number=int(2.1+2.1);
trace(num);
Will output you 4, as it would do in AS3.
I think what he meant was that int is not available as a class.
Such that the following is not valid in AS2:
var foo:Number = int(42); //valid
var bar:int = int(1234); //invalid thanks for the help guys, so now it goes to a random frame (like i wanted)
but after it transitions, i would like it to skip to ANOTHER random frame.
http://www.newgrounds.com/dump/item/913e 55afcc30ad6daeaae052045db2fe
help?
var skipped:Boolean=false;
function randomize():Void
{
if(!skipped)
{
generateRandom(Math.random()*tip_mc._totalframes);
skipped=true;
}
if(transition_mc._currentframe==transition_mc._totalframes)
{
skipped=false;
}
}
onEnterFrame=randomize;
This may do what you want.
At 1/25/12 05:11 PM, Spysociety wrote: var skipped:Boolean=false;
function randomize():Void
{
if(!skipped)
{
generateRandom(Math.random()*tip_mc._tot alframes);
skipped=true;
}
if(transition_mc._currentframe==transiti on_mc._totalframes)
{
skipped=false;
}
}
onEnterFrame=randomize;
This may do what you want.
no, that didn't do anything...