Controlling The Odds Of Math.floor(Math.random()
Hey,Is there a way to set a random number in a array to showup maybe once a day. Or every 5000 views or loops, or something like that. I would love to be able to control the odds of a array. Cheers! ActionScript Code: var pic_array = new Array(); pic_array[0] = "images/1"; pic_array[1] = "images/2"; pic_array[2] = "images/3"; pic_array[3] = "images/4"; pic_array[4] = "images/5"; pic_array[5] = "images/6"; pic_array[6] = "images/7"; pic_array[7] = "images/8"; pic_array[8] = "images/9"; pic_array[9] = "images/10"; pic_array[10] = "images/11"; pic_array[11] = "images/12"; pic_array[12] = "images/13"; pic_array[13] = "images/14"; ranNum = Math.floor(Math.random()*pic_array.length); holder_mc.loadMovie(pic_array[ranNum]+".jpg");
ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 04-06-2007, 04:52 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Math Random And Floor
Hi all
Code:
rects[i].graphics.beginFill(Math.floor(Math.random( )*0xFFFFFF), 1);
I can't find , what floor and Math.random( ) do to this code.I have a reference .
Thanks advance .
Math.ceil Ll Math.floor
Hi there,
I have code to dynamictween my mc's.Works great.I only need the if statement to work so when my square reaches it's new size and position I can load in my content using a holder.Can someone help me out on this if statement.
and instead off scaling the holder,etc I want to control it's xy position when hitting but0,...
but0.onRelease = function()
{
_root.square.dynTween({duration:6, _y:[350, "In", 60], _yscale:[200, "out", 5], callback:"_root.action1"});
if (Math.ceil(this._dynTween) == Math.ceil(_root.square) || Math.floor(this._dynTween) == Math.floor(_root.square)) {
if (_root.squareTrigger == 1) {
if (_root.squareLoaded == undefined)
_root.square.squareHolder.loadMovie("content0.swf" );
_root.square.squareHolder._xscale = 33;
_root.square.squareHolder._yscale = 33;
_root.square.squareHolder._x += 35;
_root.square.squareHolder._y += 35;
_root.squareLoaded = 1;
}
_root.square.squareHolder._visible = true;
_root.squareTrigger = 1;
}
}
}
Grtz,
Math.floor?
Hi!
what is math.floor?
what do it do?
and, how shuld I use it?`
thanks
Albert
Math Floor
Hey al since the other game iv'e been trying to make was hard and no one knew Multiple hitTest,and iv'e been working on it or like a week or less//
I feel like i should make a cool City drager...
So if someOne can rust me up on this kinda code..
Mathfloor/
To drag a obkject then stop on the grid say size 30 and
maybe you guys can whip up a FLA..
Plz someone will help son i hope...
Ill be on my computer..l.........;,,,,l
Math.floor Loses 0
I have a captivate player that checks the time I run into the problem when I use the Math.floor to round the numbers it drops the 0 if for instance the time is 9:01, 9:1 is displayed. Another Example is 2:00 is displayed 2:0 It only does this if there is a 0 before the last number.
Here is part of my code
Code:
this.onLoad = function ()
{
capPath = _parent.target_mc;
m = Math.floor(capPath.rdinfoCurrentFrame/30/60);
s = MathDigits(Math.floor(capPath.rdinfoCurrentFrame/30%60));
tempo = m+":"+s+"/"+Math.floor(capPath.rdinfoFrameCount/30/60)+":"+Math.floor(capPath.rdinfoFrameCount/30%60);
}
[MX04] Math.floor Help
Hi! I have the below code to trace the current time in seconds. But I don't know why I can't use Math.floor to round up the "currenttime" digit...
But I could use Math.floor(12.123);
function updateTimer():Void {
currenttime = getTimer();
currenttime = currenttime /1000;
Math.floor(currenttime);
trace(currenttime+ "NEWTIME");
}
var intervalID:Number = setInterval(updateTimer, 1000);
Can anyone please help??
Thanks!!
[CS3] Help With The Math.floor Command
I have a project that has a calculation that come back with a number like 10.5. I need to round down a variable and get rid of the .5 using math.floor but i can't seem to figure out how to do it.
Thanks for the help
Global Math.floor()
Hi there is there a way to globally assign Math.floor() or Math.round() to a flash presentation, so that all values in the presentation are rounded off?
Weirdness In Math.floor
project width is 500
tile_width=25;
map_collumns=Stage.width/tile_width
trace(map_collumns)
Sometimes I get a decimal return. Then, when I close it,and run it again, it shows the correct answer.
Why is this?
Math.floor To Display Two Zeros
Anyone know of a way (or better way than I am doing it) to get Math.floor to display two numbers if the Math.floor integer is 0? Math.round seems to return only one zero also.
Currently I have a condidtional to check
Code:
myNum = Math.floor(myVar/1000);
if(myNum == 0){
myNum = "00";
}
Thanks,
Ivan
Math.floor, Variables.........fun Stuff
hey guys, if i'm trying to determine a destination frame for a button to refernce (gotoAndPlay) based on a percentage, would it be necessary for me to use Math.floor to make sure the result of the percentage is a whole number before trying to send the movie to the frame?
as some of you know, i've been working on upgrading a video player peice by piece for about a week now and i think i'm getting close to the end (finally). anyway, i'm currently working on a progress bar that is draggable to control the position of the movie. anyway, i've got all kinds of functions and variables that, to be honest, i dont really know anything about beyond what they're supposed to do based on what you guys have told me on here........anyway, one such example is an equation that calculates the appropriate frame for the movie based on where the user releases the progress bar handle (i.e. _x of the handle/160; 160 being the max _x for the handle, then multiply that result by the total frames of the movie). i ran a trace, and that part seems to output correctly, but in MOST cases it outputs something like 506.134882..........(random example).
anyway, what i was thinking is that maybe i need to round that number to the nearest whole number because there's no such frame as xxx.134. does that make sense?
if that IS the case, is it legal for me to simply add that into the AS phrase that tells the movie to go to that frame, or does it have to be included into the equation itself?
here's the two lines in question:
ActionScript Code:
var vidPercentTwo:Number = (_root.sliderMC.handleMC._x/160)*_root.tutVideo._totalframes;
_root.tutVideo.gotoAndStop(Math.floor(vidPercentTwo));
these are both included into the function for the release of the button.......basically i guess i need to know if i'm on the right track w/ the Math.floor business and can i actually include the variable name in the Math.floor() as i did in the example above, or will that give me problems??
i'm off work now, so i'll be offline till tomorrow morning, i'll check up on what you guys think then...thanks so much!!
-james
Easy(?) Question About Math.floor(x);
I get undefined when I try this code:
x=12.5
trace(math.floor(x));
Are expressions allowed in the operator? or what am I doing wrong?
Thank you very very much!
Math.floor Simple Question
Hi Again-
For some reason my math.floor function is not working (trace yields "undefined")... Im sure its something simple, but Im not seeing it. Suggestions??? Thanks!!!
ActionScript Code:
thumbNum = 26;total = thumbNum * 200;wholeSteps = math.floor(total/600);trace (wholeSteps);
Math.floor/ceil Not Working?
OK... I cannot get "this.dx" to either round down OR up? It keeps tracing out as decimal.
Code:
if (this._x>(rightwall-(this._width/2))) {
this._x = rightwall-this._width/2;
this.dx *= -.9;
Math.ceil(this.dx);
trace(this.dx);
rotateDir = "left";
}
// hit the left wall
if (this._x<(leftwall+(this._width/2))) {
this._x = leftwall+this._width/2;
this.dx *= -.9;
Math.floor(this.dx);
trace(this.dx);
rotateDir = "right";
}
anyone know what gives????
Cheers!
Math.floor? Round Down To Nearest 10th
Hi Folks, Math is not my friend so I need some help.
I want to round a whole number down to the nearest whole 10th.
Like 52, becomes 50. Or 49, becomes 40. Or 2005, becomes 2000.
Does that make sense? I imagine it has a math.floor approach, but I can not figure it out.
Thanks in advance for any help!!!
What Keeps My Movie From Stopping Properly? Math.floor/interval
Hey all,
this is driving me nuts.
I have a movie, in it lies a button with which I jump to another position in the _root timeline.
At that position is a stop(); command.
The movie just wont stop while this is running in another mc1 deeper in the file
:
Code:
stop();
onEnterFrame = function() {
c=Math.floor(Math.random() * (1500 - 0)) + 150;
var Interval1 = setInterval(function () {
b=Math.floor(Math.random() * (7 - 0)) + 1;
gotoAndPlay(b);
clearInterval(Interval1);
}, c);
}
What this does in the mc1 is basically creating a random number between 150 and 1500 and a random number between 0 and 7, then jumping to a random frame (numbered from 1-7) after waiting for a random time (150-1500ms).
My _root stops properly when I remove the code posted above.
Why is this happening and how can I have a mc1 in my movie which waits for a random time and then jumps to a random frame, while I want to move around in my _root timeline?
I should add, the mcs1 which wait and move to a random frame are non existent on the position I want to move to in _root.
Could that be part of the problem?
Do I have to somehow remove the wait and choose random frame to jump to function in mc1, when moving around in _root?
How would i do this?
Any help is greatly appreciated,
dual
Math.round(Math.random()*4)+1
Will this return values of 1 to 5 (inclusive).
If not, anyone know how to get random whole numbers 1 to 5?!
Cheers.
Dongle
Var I = Math.round(Math.random()*1)
this should return either 1 or 0?
but it seems to be returning something else as well and i dont know what it is???
function startXPos() {
var i = Math.round(Math.random()*1);
_root.test1 = i;
_root.test2 = t;
return i;
}
i have this just after
if (startXPos() == 0) {
startX = -500;
endX = 750;
} else if (startXPos() == 1) {
startX = 750;
endX = -500;
} else {
startX = 0;
endX = 0;
}
_root.test3 = startX;
_root.test4 = endX;
As far as i am aware this should never return 0 for these two values but it does?!?
can someone please tell what im doing wrong here?
Math.round() Or Math.random()
Is it better to use Math.round() or Math.random() reason I am asking I think I read somehwere that one was better. My problem is that I have a number of movie clips that are attach dynamically. They move randomly on the stage but for some reason they just stop moving randomly.. I think there was a post somehwere about that but cannot seem to find it.
AS2 - How To Center Flash On Page Load In Browser (using Math.floor() For Pixel Alignment)?
Last edited by gadz : 2008-10-20 at 04:41.
I need help. I have a swf that has a tiled bmp background, a movieclip (main) with all the content (except the loader movieclip) that is automatically centered on the stage at browser resize (using Math.floor() for pixel alignment). The SWF is 100% high and wide so it fills the browser, I'm using FlashScaler to show scrollbars in the browser when needed.
My problem is that when the swf loads in the browser, the loader movieclip and the main movieclip do not center on the stage of the swf until the browser window is resized manually.
On the timeline I have an actions layer with the following code:
PHP Code:
stop();
import flash.display.BitmapData;
import flash.external.ExternalInterface;
var sw:Number = System.capabilities.screenResolutionX;
var sh:Number = System.capabilities.screenResolutionY;
var tile:BitmapData = BitmapData.loadBitmap("tile");
function fillBG():Void {
this.beginBitmapFill(tile);
this.moveTo(0,0);
this.lineTo(sw,0);
this.lineTo(sw,sh);
this.lineTo(0,sh);
this.lineTo(0,0);
this.endFill();
};
fillBG();
Stage.align = "TL";
Stage.scaleMode = "noscale";
Stage.addListener({onResize:reposition});
function reposition() {
fillBG();
var mc = _root.main;
var newX = Math.floor(Stage.width / 2);
mc._x = newX;
};
reposition();
Below it I have another layer with a preloader that uses the following code:
PHP Code:
onClipEvent (load) {
total = _root.getBytesTotal();
}
onClipEvent (enterFrame) {
loaded = _root.getBytesLoaded();
percent = int(loaded/total*100);
text = percent+"%";
gotoAndStop(percent);
if (loaded == total) {
_root.gotoAndPlay(2);
}
}
And below the preloader layer, I have the content movie clip (main) layer that starts on frame(2) after the preloader is finished loading the swf.
The HTML code is the following:
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Crosswind Group</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="StyleSheet" href="style/main.css" type="text/css" media="screen,print" />
<script type="text/javascript" src="js/swfobject.js"></script>
<script type="text/javascript" src="js/flashscaler.js"></script>
<script type="text/javascript">
var flashvars = {};
var params = { scale: "noScale" };
var attributes = {};
swfobject.embedSWF("main.swf", "flashmovie", "100%", "100%", "8", false,
flashvars, params, attributes);
</script>
</head>
<body>
<div id="flashcontent">
<div id="flashmovie">
<h2>SORRY!</h2>
<p>We have detected that you do not have the Flash Player plugin
required to view this website.</p>
<p>Download the latest <a href="http://www.adobe.com/shockwave/download/
index.cgi?P1_Prod_Version=ShockwaveFlash">Flash Player</a> for free!
It takes just a few minutes to download and install.</p>
</div>
</div>
<script type="text/javascript">
scale = new FlashScaler("flashcontent",500,620);
</script>
</body>
</html>
And the css is:
PHP Code:
html {
height: 100%;
font-size: 100%;
overflow:auto;
}
body {
height: 100%;
margin: 0;
padding: 0;
background-color: #000;
color: #fff;
font-size: 76%;
font-family: "Courier New",Arial, Verdana, sans-serif;
}
a {
color: #666;
text-decoration: underline;
}
h2 {
margin-top: 2em;
}
#flashcontent {
overflow: hidden;
}
#noflash {
margin: 20px;
}
Here are the complete project files. (see attached zip file).
Attached Files
MATH: General Math Ratio Formula?
So I have these sets of values that correspond with other values. But the manufacturer only gave me sets by 5. I need to break it out for every integer. Here's what I got ...
Code:
20=35
25=54
30=78
35=106
40=138
45=175
50=216
55=261
60=310
My question is how do I develop a formula in Flash that can give me values for numbers not divisible by 5? Accuracy to the nth power, figuratively speaking, isn't crucial.
Big thanks,
Layne
Math.random()
hi ... does anyone know how i can generate a random number between -5 and 5 using math.random() ?
its got to be easy but i cant work it out ...
thanks ... thesquirrel
Math.random();
Hey guys big problem here. I am trying to use the Math.random(); command to generate a 1 or a 0. What I have so far is in the first frame of the MC, on actionscripts:
number = "Math.random()";
Then next frame I have stop. The text field in the next frame is dynamic and the variable is set to "number". When I go to export this, all I get is a blinking "C"...I guess C stands for confused . Also when I do a trace on the variable "number", all it returns is "Math.random()".Anyways, I am stumped and am wondering what I am doing wrong.
I thank you for any help in advance.
[Edited by dracen on 01-29-2002 at 09:48 PM]
Math.Random
I am having trouble, actually I don't know where to start. I am trying to use the Math.random command but I don't know how specify it to become a whole number. I also don't know how to specify the range of the random number that I'd like to get.
For the sake of argument I would like to retrieve a value from 1 to 3.
Please help, I'm just trying to get accustomed to AS
Thanks
Math.random
Hehehe.
I program for C++ JAVA and VB.
but i still cant figure out how Math.random works in
FlashActionScripting.
by reading these here threds.
so IF anyone has a .fla out there, i could DONWLOAD
it would be great,
http://www.JediMinds.Com
Math.random
I need to know how you can use the following script and have it round to the nearest whole number.
variable = [math.random() *12]
Thanks!
Math.random & If
Should this work in flash MX actionscript?
FRAME 1
display = Math.round(Math.random()*2);
FRAME 2
if (display == 0) {
loadVariables("00_ComputerText/00_Home.txt", "");
}
if (display == 1) {
loadVariables("00_ComputerText/00_01.txt", "");
}
if (display == 2) {
loadVariables("00_ComputerText/00_02.txt", "");
}
I had used it in flash 5 but can't seem to get it in MX.
Actionscript dictionary says:
--------
Math.random
Availability
Flash Player 5. In Flash Player 4, the methods and properties of the Math object are emulated using approximations and may not be as accurate as the non-emulated math functions supported by Flash Player 5.
Usage
Math.random()
Parameters
None.
Returns
A number.
Description
Method; returns n, where 0 <= n < 1.
--------
I am essentially randomly picking a txt file by picking a random number. Any other alternate actionscript methods are welcome suggestions.
Thank you thankyou.
Math Random
hey guys. i have a background image on my main page. i'm going to place that background image into mc and then add 4 frames to the mc. on the first frame i want it to choose a random frame to go to and then to go to the frame (in the mc). each frame will have a different background image. what i want is to know what code i should use for it to choose the random frame!
thanks
HELP Math.random
Hey there!
I'm making a game thats like a high tech PONG, and when ever the player starts a new game I want the ball to start in a different position. This is the code I'm using but I guess I don't know how to use it.
code: _x = Math.random()400-600;
_y = Math.random()200-300;
I want it to randomly pick an _x position HIGHER than 400x and LESS than 600x. And I want the _y to randomly pick HIGHER than 200y and LESS than 300y. Can someone help?
Thanks ahead of time, and here's a donut.
Math.random()*100+200
I use this:
code: Math.random()*100+200
a lot but i don't understand it. How does it only choose a random number between 100 and 200?
It doesen't make scence to me.
Thanks
Jœ
Math.Random Help?
Okay, so maybe it's late or maybe I've just been working on this project too long... but I can't seem to remember how to use the math.random function to do what I'm trying to do. I'm using Flash MX and I have a movie clip which will eventually have 24 labeled keyframes (beta1, beta2, beta3, ...) as marking points. When the movie clip starts playing I want to randomly jump to one. How do I use Math.random to make this happen? I know it also Math.floor but I can't seem to remember how the two go together! Please advise. To help you visualize the idea, the movie is attached. Note that only half of the markers are labeled so far! Thanks for your help in advance.
Sleep weary,
M. Vaughn
Can't Get Math.random...
The code below will display all the pictures where I want them on the stage but I can't get them to randomly display the pictures. I know that whatever I am doing wrong is simple but I don't get it!!!
// list of pics
picList = ["e1_mc","e2_mc","e3_mc","e4_mc","e5_mc","e6_mc","s 1_mc","s2_mc","s3_mc","s4_mc","s5_mc","s6_mc"];
x = 0;
y = 0;
for (i=0; i<picList.length; i++) {
myNum = int(Math.random()*picList.length);
this.attachMovie(picList[i], "p"+i, 5+i);
this["p"+i]._x = x*132+35;
this["p"+i]._y = y*62+30;
x++;
if (x > 2) {
x = 0;
y++;
}
}
stop();
Using Math.random()
using math.random is it possible so that it doesnt go below 30?
i am using it to tween alpha and it fades in and out depending on the random number but i never want it to drop below 30? but from 31-100 it is random.
thanks
Math Random From -6 To 6 ? How Do You Do It
Hi at the moment im making a game, the problem that i have is that i cant make a math random from inbetween (-6) to (+6) all i can do is say
random(6)
or
Math.random() * 6
but i dont know how to make the random number be inbetween the negative aswell.
Math Random
I am try to send my movieClip popped1 to a random frame between 2 and 4.
on (release) {
var i = Math.random()*2+2;
popped1.gotoAndPlay(i);
}
???????not working???????
Math.random()
Could someone please give me an example of how to use Math.random() correctly. I know that the random(n) - function gave me a number between 0 and n-1. But somehow Math.random() gives me a number between 0 and 1. Now how ist the correct example how to use it If I for example want a number between 1 and 5.
Waitin eagerly for the answer
Math.random()*
is there a way 2 use Math.random and define the range of randomness ?
4 example: get a random # between 20 and 50. cuz usually it starts @ 0.
thnx, !!~~
Math.random
error
Edited: 08/18/2008 at 01:49:33 PM by samunick
Math.random
hi Married woman i'm Luciano how are you i hope you fill good ,i have a problem to store a number inside an Array.
I would like to store some number in an Array but i can't resolve this problem because when i randomize a number i'm not to be able to diversify a number stored inside in a array.
I would like to know if is possible to resolve this problem because i try a lot of time but i have still not resolve this problem because when i activate a trace and when i check a number inside an array i reply two number equal
for semplify my problem i can attach my code:
so i'm glad to inform that you are very kind to they give to me straight;
thanks a lot Luciano
Attach Code
var Leng:Number = tempArray.length;
for (var f:int = 0;f< Leng; f++){
var RndNumA:Array= [];
var RndNumB:* = Math.floor(Math.random() * Leng );
if(RndNumA[f] != RndNumB)
RndNumA.push(RndNumB);
}
Math.random()
hello people how can i place my letters in a different position everytime the game starts and the letters will not appear in the same position? right now i can make them appear in different positions but sometimes they will appear in a same position. can anyone help me solve this problem?
i got the fla file attached here. thx
Math.random
ive got a load of small thumbnail images in a library and i want to display a random 50 of them on the stage when a generate button is pressed. I was going to do it by placing 50 empty movie clips on the stage and then have each one of them load a random one of the jpegs using a code a bit like below:
on (release) {
filename = ["thumb1.swf", "thumb2.swf", "thumb3.swf", "thumb4.swf", "thumb5.swf", "thumb6.swf",etc.....];
i = filename.length;
k = Math.floor(Math.random()*i);
loadMovie(filename[k], "_root.screen_mc");
}
However im not sure how to adapt this to load into 50 empty mcs at once without just copy and pasting it 50 times!!!!!!!!! There is also the problem of duplicates ( different mcs showing the same thumbnail) ...im not too worried about this but if there is a way around it id love to know how.
THANKS ALL.
Math.random()
does math.random return a 0 or a 1, or does it return 0,0.1,0.2...1?
just curious as im using a code with (math.random()*10)+5;
but if it only returns a 0 or a 1 its not that random as it will either be 5 or 15,
just wondering is all!
thanks
Math.random()
besides Math.random(), is there another way to specify a range of numbers, say between 0-100,
Math.random()
hello people how can i place my letters in a different position everytime the game starts and the letters will not appear in the same position? right now i can make them appear in different positions but sometimes they will appear in a same position. can anyone help me solve this problem?
i got the fla file attached here. thx
Math.random()
trying to generate random numbers of 1,21,41,61,81,101 -- can ONLY be those numbers.
this code works: Number(random(6)*20)+1;
but isn't this code old?
what would the new MX code be?
Math.floor(Math.random() * 20) + 1; // help
Math.random With
Hello all,
I have to move a bicycling charachter animation forth and back around the screen; I wish to simulate its movement scrolling the scenario on the back (green and pleasant mountains, for example).
I'm wondering if it's possible to get an ever-changing scenario dropping mountains shapes a bit out of the stage and letting them come inside, in a continous sequence, WITH A RANDOM APPEARANCE: I thought I can do it with populating an array with a pack of library symbols, and combining it with a math.random - function, but I'm a little stuck with it: must I use also a for cycle?
I don't if this is the right approach. Anyway any help will be very appreciated
thanks in advance
Ninetta
Math.random()
I'm a little curious about the Math.random function and how flash generates random numbers? I made a simple .swf that simulated the roll of a 2 dice, but how random is it really? It just doesn't seem to be truly random. If anyone knows anything about this I would like to know.
|