Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rate Thread Display Modes
Old 06-02-2011, 06:09 AM   #1
Andrew the Great
Senior Member
 
Join Date: May 2011
Posts: 100
Default [AS2] help with going to random frame

okay, so when i press my mc (random1) i would like it to go to a random frame (but only random between frames2, 18, and 24) for different maps in my game.

This is the formula i have right now but it doesnt work, (the formula works to go to any frame tho with a frame number where () is and not (math.random) and not sure if i was supposed to put something else besides math.random

I've also tried other things like ((random (2)) , (random (18)), (random (24)))
and also (random ( 2, 18, 24)) and none of them seem to work =/
any help would be greatly appreciated!
thanks, Andrew


ActionScript Code:
this.random1.onRelease = function(){ gotoAndStop(math.random( 2, 18, 24 ));// want it to choose a random frame of 2, 18 or 24 }
Andrew the Great is offline   Reply With Quote
Old 06-02-2011, 08:52 AM   #2
neilmmm
Senior Member
 
neilmmm's Avatar
 
Join Date: Oct 2005
Location: dorset
Posts: 1,637
Default

Code:
var frameArray:Array=new Array(2,18,24)
random1.onRelease = function(){
gotoAndStop(Math.floor(Math.random()*frameArray.length));
}

Last edited by neilmmm; 06-02-2011 at 11:27 AM.
neilmmm is offline   Reply With Quote
Old 06-03-2011, 04:25 AM   #3
Andrew the Great
Senior Member
 
Join Date: May 2011
Posts: 100
Default

this doesnt work for me dude =/ it either goes to frame 2 or goes to the main menu (frame 1)
Andrew the Great is offline   Reply With Quote
Old 06-04-2011, 08:47 PM   #4
neilmmm
Senior Member
 
neilmmm's Avatar
 
Join Date: Oct 2005
Location: dorset
Posts: 1,637
Default

You may need to add scope to the gotoandstop

Ie this. this._parent or even the non recommended _root
I have not tested the code but can not see a problem in it.

Perhaps you should post an Fla.
neilmmm is offline   Reply With Quote
Old 06-04-2011, 11:47 PM   #5
Andrew the Great
Senior Member
 
Join Date: May 2011
Posts: 100
Default

I've solved why it wasnt working took me a bit of messing around with but basically your code is 90% correct i found two things that work option 1 is:::


ActionScript Code:
var frameArray:Array=new Array(2) var frameArray:Array=new Array(18) var frameArray:Array=new Array(24) random1.onRelease = function(){ gotoAndPlay(Math.floor(Math.random()*frameArray.length)); }


option 2 is:::


ActionScript Code:
var frameArray:Array=new Array((2,18,24)) random1.onRelease = function(){ gotoAndPlay(Math.floor(Math.random()*frameArray.length)); }


thanks for your help with random frames =]]




EDIT::
this code still makes it go to frame one some times and im not sure why (as if it randomly chooses frame 1, or the other 3 frames i have listed in the array)

Last edited by Andrew the Great; 06-05-2011 at 12:08 AM. Reason: forgot to mention something
Andrew the Great is offline   Reply With Quote
Old 06-05-2011, 09:26 AM   #6
neilmmm
Senior Member
 
neilmmm's Avatar
 
Join Date: Oct 2005
Location: dorset
Posts: 1,637
Default

i am sorry i did make a mistake try ... should have tested... i must have been v tired

Code:
var frameArray:Array=new Array(2,18,24)
random1.onRelease = function(){
var target:Number=Math.floor(Math.random()*frameArray.length)
gotoAndStop(frameArray[target]);

}
stop();
see fla

hope it helps

btw both your solutions are incorrect both will make an array 24 undefined instances
neilmmm is offline   Reply With Quote
Old 06-05-2011, 09:27 AM   #7
neilmmm
Senior Member
 
neilmmm's Avatar
 
Join Date: Oct 2005
Location: dorset
Posts: 1,637
Default

still rushing no fla
Attached Files
File Type: zip random frame.ZIP (4.9 KB, 216 views)
neilmmm is offline   Reply With Quote
Old 06-05-2011, 06:10 PM   #8
Andrew the Great
Senior Member
 
Join Date: May 2011
Posts: 100
Default

sweet! thanks, this works and it doesnt go frame 1 at all =] (ill check out your .fla right now)

edit: yeah your .fla works same as mine( i needed this for random maps on the different difficulties, and then a random option for random difficulty and random map) thanks again!
Andrew the Great is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:55 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.