Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




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?



FlashKit > Flash Help > Flash Newbies
Posted on: 07-04-2006, 07:34 AM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

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

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.

What Is The Diffrence Between Math.floor And Math.round
Hi Guys,

Wat is the diffrence between these two?

I looked at the help, but i still dnt quite understand it!

Math.round And Just Plain Math
Hi, I'm back with another question.

I want my exam to show a percentage at the end. I guess I'll concatenate a 'percent sign' at the end, but right now I'm having trouble with the math.

There are 13 questions. This is what I have:

score = Math.round(right/13*100);

The scores are coming out all wrong. Any ideas would be greatly appreciated.

Dan

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");

Math.round Or....?
Hi there,


This is a part of an as-script for a poll:


percent1 = Math.round(value1);
percent2 = Math.round(value2);
percent3 = Math.round(value3);
percent4 = Math.round(value4);
v1 = Math.round(value1) add "%";
v2 = Math.round(value2) add "%";
v3 = Math.round(value3) add "%";
v4 = Math.round(value4) add "%";

Now i want the sum of (v1+v2+v3+v4) to always equal 100. How do i accomplish that?

any suggestions?

D-Flyer

Math.round() HELP PLEASE
Right guys if you have a look @ the loink you will see what iam talking about. For some reason the window won't go to targetx and targety plus it woin't round down either.
www.innovativedesigns.org.uk/untitled.htm

_y += Math.round(vf-_y)/5;
I tried the Math.round too, but… the text keeps blurring....

(I already read all the threads about “blurred scrolling pixel fonts” to check if my question was already made and answered)
I have this movie with Y sliding and X sliding which is having an specific blurring problem when sliding backwards in the case of Y sliding and when sliding forwards in the case of X sliding.

All the text boxes and the movies that contain them are set up to integer coordinates. It seems as there is something with the code that is placing the slider in a non-integer coordinate after clicking…. Any ideas? Thank you very much.

PS: I’m referring mostly to the text when stops since while sliding the blur is visible in any direction. It would be great if I can solve that too but by now I would be happy to solve just the text when stops.

The code (written in “base” mc) for the Y Slider is:

onClipEvent (load) {
vf = 314;
}
onClipEvent (enterFrame) {
_y += (vf-_y)/5;
}

each button has this code to move the slider (in which “base” is the instance name of the movie that contains the text and loads the pics)

first button:

on (press) {
base.vf = 314;
}

second button:

on (press) {
base.vf = 38;
}


And so on…

The code (written on “base” mc) for the Y Slider (located inside “base”) is:

onClipEvent (load) {
vf = 0;
}
onClipEvent (enterFrame) {
_x += (vf-_x)/5;
}

each button has this code:

first button:

on (press) {
base2003.vf = 0;
}
second button:

on (press) {
base2003.vf = -180;
}

And so on…

Math.round()
is it possible to do a Math.round that doesn't round to the nearest whole number, but to the nearest half number?

Ex:

Math.round(5.6)=5.5

NOT

Math.round(5.6)=6

Thanks

Math.round()
is it possible to do a Math.round that doesn't round to the nearest whole number, but to the nearest half number?

Ex:

Math.round(5.6)=5.5

NOT

Math.round(5.6)=6

Thanks

Using Math.round
Hello all,

I amm trying to use math. round so that the following piece of code will reposotion it's target object on an integer rather than a fraction. Can anyone tell me how to add that to this code?

Thanks much!
SumSum

// Keeps the MENU in place when the movie is resized.
menuMC.onResize = function () {
this._x = (Stage.width/2)-390;
this._y = (Stage.height/2)-185;
}
// Register titleClip to be notified when movie is resized.
Stage.addListener(menuMC);
// Set initial position of title clip.
this.menuMC.onResize();

Math.round 0.25 0.5 0.75
Hi,

I am trying to round of a number so that it displays as 1, 1.25, 1.5, 1.75, 2 etc
I have it rounding off to 2 decimal places with:

temp = Math.round(temp * 100) / 100;

but thats not quite what I want,

Any idea? Thanks,

Math.round
Gday,

Im having a hard time getting my head around this, and I feel stupid for posting this, but any help would be good

using Flash 8,

want to round a number to the nearest 40, here is the macromedia live doc syntax

public static round(x:Number) : Number

This is my first attemp to learn actionscript 2.0. so what is

public static?,

And how do I use this?

Cheers, James

Math.round - Flv ?
I have been using the following code for playing flv's however I always run into a problem when the actual obj.duration is close to a half increment. Example, the actual video length is 15.53 seconds.

So the Math.round(_global.videoDuration); will round up to 16, where as the Math.round(ns.time); at the end of the video shows 0. This means that my IF statement never fires.

My solution to this problem has always been to go back into the video file and add a little bit of black video so that it doesn't end up on a half increment.

Now here is my question, is there a better way to set up the onEnterFrame function so that I don't have to adjust the video file?


ActionScript Code:
_root.stop();
var netConn = new NetConnection();
netConn.connect(null);
var ns = new NetStream(netConn);
my_video.attachVideo(ns);
ns.setBufferTime(5);
ns.play("videos/Final Surgical OptionCD.flv");
//
getTotalTime = function () {
    ns.onMetaData = function(obj) {
        _global.videoDuration = obj.duration;
        trace(obj.duration);
    };
};
// monitors the current position of the playhead against the total playing time
onEnterFrame = function () {
    getTotalTime();
    totalPlayingTime = Math.round(_global.videoDuration);
    currentPlayingTime = Math.round(ns.time); //;
    trace("currentPlayingTime "+currentPlayingTime)
    trace("totalPlayingTime "+totalPlayingTime)
    if (totalPlayingTime == currentPlayingTime) {
        //ns.seek(0);
        // ns.pause();
         ns.close();
        // ns.play()
         //gotoAndPlay("start");
    }
};

Math.Round
Hi all ,
I am using a script of..

letitbe = (Math.round (num))

this round 's off to the nearest whole number , How can I round off to the nearest 100?

Thanks in advance.





























Edited: 11/27/2007 at 11:09:44 AM by Balloony2

Math.round Help
Hi,

I have a nuber= 0.00999999995 and i need to round it to 0.01.
I mean round the numbers but with 2 digits of presition.

any ideas?

tks

Math.round
Hey, can you set the precision at which Math.round works? thanks.

Math.round()
Hi

I have a problem facing might seems very small but just couldnt do it.
I want to roundup a value up to one decimal only. For example,
x=100.238294;
trace(Math.round(x*10)/10)
this works fine but if the number is : 100.0000000000

then I want my output to be 100.0. But its showing 100 only. Does anyone knows how to get this done or any other way to do it. Please let me know .Thanx

Ashish

Math.Round()?
What is math.round() do? In kirupa's Random numbers tutorial, he explained the use of math.floor(), but said round() was for another time. Yet I see that, and not .floor() in use in the random movement tutorial.

What is it? What does it do?

Math.round()
quick question

how do you round a number to 4 digits...

so 3.45356345345
is 3.456
and 1
is 1.000


//VoS

Math.round
How to round the figures for percentage loaded?

onEnterFrame = function () {
var percent_loaded = _root.getBytesLoaded()/_root.getBytesTotal();
preloader_mc.value = percent_loaded;
_root.info.text = percent_loaded * 100;
if (percent_loaded == 1) {
delete onEnterFrame;
gotoAndStop(2);
}
};

[help] Using Math.round()?
I'm not sure how to use the Math.round() function in Flash?

Im trying to take a value from a dynamic textbox on the stage and round that number off to a whole number.

I would really appreciate some help!

Math.round
Hey, can you set the precision at which Math.round works? thanks.

Math.round()
Hi

I have a problem facing might seems very small but just couldnt do it.
I want to roundup a value up to one decimal only. For example,
x=100.238294;
trace(Math.round(x*10)/10)
this works fine but if the number is : 100.0000000000

then I want my output to be 100.0. But its showing 100 only. Does anyone knows how to get this done or any other way to do it. Please let me know .Thanx

Ashish

Math.Round()?
What is math.round() do? In kirupa's Random numbers tutorial, he explained the use of math.floor(), but said round() was for another time. Yet I see that, and not .floor() in use in the random movement tutorial.

What is it? What does it do?

Math.round()
quick question

how do you round a number to 4 digits...

so 3.45356345345
is 3.456
and 1
is 1.000


//VoS

Math.round() HELP PLEASE
Right guys if you have a look @ the loink you will see what iam talking
about. For some reason the window won't go to targetx and targety plus it
won't round down either.
www.innovativedesigns.org.uk/untitled.htm

Math.round(); Question
hello,

is it possible to round a floating point number to a certain
value?

what i mean is:

i want to round 1.85038723 to 1.8504

(skip the last 4 numbers).

is there a possibility?

thx

Math.round Not Working
I'm making one of those image viewers where the frame resizes to fit the image. I'm still quite far off finishing but I've hit a problem already.

I can't get the frame width and height to exactly equal the img width and height. It's always .05 out or something, even though I'm using Math.round!!

I've attached the movie and the text file from where the image details are stored.

In the bottom left of the movie have 4 vars which you can watch as it resizes. first2 top and bottom are the width and the height of the frame. The next two top and bottom are the number it increases or decreases the frame by.

If the equation works these text boxes disappear because it moves to the next frame (where it would show the image when I get that far.)

The 2 buttons in the right corner are to swap between the 2 pretend images.

Hope someone can help me. It's an MX file but can send a flash5 on request.

I don't want the whole thing done for me....just pointers on what I'm doin wrong.

Cheers

Math.round Question
Hi
Can anyone tell me why the following use of
Math.round(Math.random())does not work and suggest how I can get it to work, please.

myQuote=new Array(new Array(”one”, “two”, “three”), new Array(“four”, “five”,“six”));
myQuote=Math.round(Math.random()*(myQuote.length)) ;

Thanks in advance.
John
jdshipton@rogers.com

Math.round Function
i'm just messing arround with it but i can't get this thing to work.

if i have some script like

_level0.number=random(51);

how can i then round this number to the nearest 5?

I don't just want to use _level0.number=random(11)*5
cos then i find out how to use round

so far i have something like math.round(level0.number)50; but i can't really remember

plz help if u can (i'm using flash 5)
==================
TiMo

Math.round Question
I want to round a number to the nearest .5 (example: 12.0, 13.5, etc.). The round method only rounds to the nearest integer. Any ideas?

Thanks.

Math.round Alternete
is there a math round that only returns multiples of ten?

Math.Round Probs
when u use math.round

5.6 will be 6
and 5.2 will be 5

i want 5.6 to be 5
5.9999 is also 5

how do i round down till whole number?

thx in advance

A Little Trouble With Math.round();
im having trouble getting the right code for this do i need to extend the code from the dynamic text im trying to round to this math??

Math.round(undefined)
Hello!
I have a problem with the Math.round function. When I write


Code:
Math.round(undefined)


it returns 0 (zero)?!? Shouldn't it returns NaN or somethings??

Thanks for your help!

Still Having Problems With Math.round...
Thank you for viewing this thread. I'm trying to create a file that has the playhead gotoAndPlay() a random frame, then return to the initial frame, gotoAndPlay() another random frame, a. s. o. Feel free to view the attached file if my explanation befuddles you It works fine to the point when "0" (the "start" frame) is chosen as the random frame. How could I go about changing the script so that exclusively frames "one", "two" and "three" are addressed?

Thank you for your help!

Math.round Question, Please Help
I understand how to round up/down to whole numbers - but what if I want to round a whole number up/down to a multiple of five?

I have a slider that also has a percentage read-out, I'd like the percentage to always display a multiple of 5 - so, 0$, 5%, 10%, etc.

The percentage is based on the x coordinate of a dragable movie-clip.

Please help!
Send immediate responses to rob.marston@fox.com - thank you.

Math.round Problem
Hi there,

I want to round with 1 decimal.

For example:
1.01 --> 1.0
1.26 --> 1.5
1.74 --> 1.5
1.76 --> 2.0

Can anyone help please?

Greetz Arjan

Math.round Question
I'm using this code on an empty container which loads content from an external swf. I added the Math.round so that when the container slides the pixel font stays clear.

ActionScript Code:
onClipEvent (load) {Xpos = 170;}onClipEvent (enterFrame) {Xa = _root.container1._x;Xdiff = Xpos-Xa;Xmove = Xdiff/7;_root.container1._x = Math.round(Xa+Xmove);}

The problem is that now the slide stops or too early or too late of a pixel, enough for not aligning with the rest of the elements on the page.
Is there a way that if Xa+Xmove = 17.2 it goes 17 (normal Math.round)and instead if Xa+Xmove = 17.8 it goes 18?

Math.round Rounding Up?
is there a way to always round up? (1.1 = 2 not 1)??

Math.round Problem
I have the following Problem ...

Got sum mathematical stuff and I got sumthing like

432.6748432 and need 432.67 (keeping the 67 coz the number 3 is 4)

or i have

432.6774832 and need 432.68 (rounding up depending on the 3 Number after the point)

any hints??

thanx in advance

Help With Math.round Function
Hi there,

I'm not sure about the title of this thread, but I'm assuming that I'll be able to somehow sort my problem with the math.round function.

Screenshot :


I have a small mp3 player. The part with the red outlining in the screenshot shows the current playing position in seconds and minutes. Right now it shows "0:6". What I want to do is to make this "00:06" and then when it reaches 10 seconds, it should show "00:10". How can I do this?

I'm currently calculating it this way :


HTML Code:
var pos_total = song.position/1000;
var pos_minutes = Math.round(pos_total/60);
var pos_seconds = Math.round(pos_total)%60;
...where "pos_minutes" is the minutes and "pos_seconds" is the seconds.

All help will be greatly appreciated! Thanks

Math.round() Inconsistency
Hey folks,

I was writing a really quick significant figure function the other day, and for speed just slapped this down:
Code:
Math.dPlaces= function (n,f) {
n = n * Math.pow(10,f);
n = Math.round(n);
n = n / Math.pow(10,f);
return n;
}
No problem so far ... just move the decimal point the right number of places in your number, do a "standard" Math.round(), and then put the decimal place back. Easy.

However, it's the Math.round() in this example thatr is behaving rather oddly, round 1.5 *down* to 1, rather than (as it usually does) *up* to 2.

Here's an example (using the above method):
Code:
trace ( Math.dPlaces( 1.005,2) ); // ouputs 1
Now this is very strange. Tracing all the values in the function show you that you are (as you should be) doing this in the second line of the function:

Math.round(100.5)

But inside this prototype Math.round(100.5) gives you 100 not 101.

If you try:

trace(Math.round(100.5))

you'll get 101.

Why does this change when you are operating inside the function does the return from Math.round change? It doesn't make any difference if this is a prototype of the Math object or just a normal function.

Even *more* weird is putting in this:

Math.dPlaces(100.005,2)

which *correctly* outputs 100.01!

Well, it's no huge deal, but I'm damned if I can see why Math.round(100.5) should give different returns.

How Does Math.round Work?
what up people?

I was wondering how is it that i can use math.round.

Currently im working on a script that eases a pixel font. When the animation is over the text is blurry. Meaning that its not on an exact pixel. I was wondering if anyone knows if i could use math.round in order to make it round off to the nearest pixel.

thanks yo

ActionScritp And Math.round Function
I want to create a graph (vertical bars) that i can control by sliding a scroll button up and down (the bar would follow the scroll button). On my scene i have a movie clip (instance name = panel) that as 20 frames. It is controled by the scroll bar.

The button as this script:

on (press) {
this.startDrag(false, 0, MaxX, 0, MinX);
}
on (release) {
stopDrag();
}


This button is then converted into a movie clip and as this script:

onClipEvent (load) {
MinX = -20;
MaxX = 0;
mcFRAME = _root.panel;
}
onClipEvent (mouseMove) {
x = Math.round(this._y);
mcFRAME.gotoAndStop(-x);
_root.bar.input = (-x);
updateAfterEvent(mouseMove);
}


The problem is that when i move the scroll bar (with mouse button down) it works fine, the graph bar will follow. But when i release the mouse button, the panel movie keeps on moving for a very short period (0.5 sec.)when it's supposed to stop. Also, when i use the "trace" function for "mcFRAME.gotoAndStop(-x);" and "_root.bar.input = (-x);" but the values are difffrent until i release the button and wait about (0.5 sec.). I want to know if this problem is comming from the Math.round function, or from a script error ?

This is very bothering, because i want to use that scroll bar so the viewer can set the graph's bar height. But when the disired height is reached, a small modification is made event if the mouse moves even if the button is up.

Thanks

Steve

Math.round Is Messing Things Up
v: Flash MX

I can't make this work. Can anyone help

Click here and go to the portfolio section

The mc sectionDisk (which stops below the section you're in)uses this script:

sectionDisk._x = Math.round(sectionDisk._x+(sectionDiskX-sectionDisk._x)/nSpeed);

'sectionDiskX' takes it's value from the X position of the section button (eg) Broadcast, Internet, whatever, but the value it generates for sectionDisk._x changes depending on what button you come from.

So if you're in 'Other', and you click 'Broadcast', sectionDisk._x will be a different value than if you're in 'Kiosk' and then you click 'Broadcast'

This would be OK, but the number strip (which contains the links to the individual projects) needs to sit exactly centered in the disk - and it wont.

I know it's a problem with the way Math.round modifies the numbers, but I can't make it work. Can anyone help?

Weird Results With Math.Round
Click this URL for example

I get some weird results when using Math.Round (also tried .Ceil and .Floor)

code: // OnClipEvents on MCs
onClipEvent(load){
this.pos = 86;
}
onClipEvent(enterFrame){
this._x += Math.round((this.pos-this._x)/_root.easing);
}


In the example. The MC mc1 is inside mc2, which is inside mc3 etc. etc.

So I use:

code: // btn is my button instance name
_root.mc1.btn.onRollOver = function() {
_root.mc1.pos = 172;
}
_root.mc1.btn.onRollOut = function() {
_root.mc1.pos = 86;
}
_root.mc1.mc2.btn.onRollOver = function() {
_root.mc1.mc2.pos = 172;
}
_root.mc1.mc2.btn.onRollOut = function() {
_root.mc1.mc2.pos = 86;
}
// etc. etc.


So I use Math.Round to make sure the pixel font stays sharp. But when returning to the original value of 'pos' the mc doesn't stay on the exact _x = 86. It stays on a whole pixel, but not 86. I've had this problem before and had to compensate for the shift by adding or subtracting pixels when returning the mc to its original position.

I tried that here, but I get this weird effect (roll over the buttons and look at the last two mc's shift, almost vibrating.

Any ideas? Am I doing something wrong?

Your help is appreciated.

Thanks,

/Flip

OnMouseWheel + Math.round + Boundaries
Peepz,

I have a movieclip that has a height of 500 px, it starts on _y = 0, now i want to scroll it on integers with Math.round but it won't work. I also want it to stop scrolling down if he is at the bottom or the top (it behind a mask)

the tween method works fine so let it as it is...

hope somebody can help?

thanks already!


Code:
mover = 0
var mouseListener = new Object();
mouseListener.onMouseWheel = function(delta) {

mover += Math.round(10*delta);
mcTempHolder.tween("_y", mover, 1);

};
Mouse.addListener(mouseListener);

Copyright © 2005-08 www.BigResource.com, All rights reserved