Hi,
I have a actionscript calculation that initially calculates a value of infinity. Is there a “if” statement you can perform until the calculation actually calculates a real number (0-100)?
I can be more specific if needed.
Hi,
I have a actionscript calculation that initially calculates a value of infinity. Is there a “if” statement you can perform until the calculation actually calculates a real number (0-100)?
I can be more specific if needed.
Well infinity goes on forever, so how can you calculate a value for it? That is like saying that you counted to the end of infinity :-\
What is the code you are using?
yeah sounds odd, what are you doing?
There’s
isFinite(someNumber)
which checks to see if a number is, well finite (not infinite) as well as the constants
Number.POSITIVE_INFINITY
and
Number.NEGATIVE_INFINITY
if that helps any
Here is my code.
JukeBoxClass.prototype.checkLoad = function() {
var percentLoaded = (MySong._framesloaded/MySong._totalframes)*100;
if (isNaN(percentLoaded) == false){
progressbar._xscale = Math.round(percentLoaded);
if (percentLoaded<100) {
txtpercent.text = Math.round(percentLoaded)+" - streaming";
} else {
txtpercent.text = "loaded";
}
}else{
txtpercent.text = "loading.."
}
};
You can see it in action here. Scroll to the next song and for a split second it will say infinity.
hehehe… well yeah, cause the when one of the expressions you have is being evaluated its value would be infinity… i thought you were talking about an integer that is actually infinity (which actually is impossible :beam: )
percentLoaded = (MySong._framesloaded/MySong._totalframes)*100;
i guess when MySong._framesloaded is zero, dividing it by MySong._totalframes is infinity…
:A+:
Yeah I had a math teahcer that once talked about this. He said that if you take any number, for example 1, and divide it by zero, then it equals infinity.
This is because if you have something and divide it by 0 oarts, then you have everything, because nothing is divided. It’s kinda trippy, but I thought I’d share.
-brad-:evil:
oops… i got it the other way around… as leet said, when you divide a number by 0 the result is infinity, and, therefore, before the sound track is yet selected, the value of MySong._totalframes would be 0 and therefore giving an infinity…
:A+:
txtpercent.text = Math.round(percentLoaded)+" - streaming";
Just replace that line with:
txtpercent.text = isFinite(percentLoaded) ? Math.round(percentLoaded) + " - streaming" : "0 - streaming";
-Al
alethos,
Thanks. Your code worked perfect. Would you explain the code. I don’t really understand the “:” or “?” syntax.
? : is an if/then conditional statement. Its in Flash help under operators if you want to look it up there
basically it evaluates the first statement and depending on whether or not it is true returns ether the statment after the ? (when true) or the : (when false).
example:
value = (true) ? 1 : 2;
trace(value); // traces 1
value = (false) ? 1 : 2;
trace(value); // traces 2
you can compound these within one another as well
value = (a > b) ? 1 : (a > c) ? 2 : 3;
basically its an if/else all in one line returning the result of the evaluated line
Hey, glad it worked.
The ?: conditional is just a condensed IF statement really.
Instead of something like this:
if(myWallColour == "green"){
myOpinion = "pretty";
} else {
myOpinion = "ugly";
}
you could use this:
myOpinion = (myWallColour == "green") ? "pretty" : "ugly";
You don’t have to set the output of the ?: conditional to a variable, but that’s how I mostly use it. You could also put executable code after the ? and the :, but IF statements are a lot more readable if you want to execute anything.
In general, if “conditionalStatement” is true, then “ifTrue” is returned, else “ifFalse” is returned:
conditionalStatement ? ifTrue : ifFalse
Hope that cleared things up a bit (sorry, I’m not great at explaining things ).
-Al
::EDIT:: Senocular beat me to the punch. With a much better explanation.
nah yours is good, you wrote out the if else statements
Thanks to the both of you. I always say two explanations are better than one. :rambo:
you could always do an infinite loop
i think its
if(i=1; i=0; i++)
{
}
am i off topic
lol im dumb
while(true){}
Hey kaotic, I believe you were going for a for loop there, not an if statement :-\
i know
lol i had a brain fart
so many if/then/else/while commands i always get them mixed up im still a n00b man:smirk:
so then its
for(i=1; i=0; i++){
}
:: Copyright KIRUPA 2024 //--