Ask a Question related to Macromedia Flash Actionscript, Design and Development.
-
jayfromcleveland webforumsuser@macromedia.com #1
Problems with if-else statements in dynamic text
Hi,
I'm new to Flash and ActionScript and have never previously done programming. However, I have a technical degree and experience and have a clear idea of what I'm trying to get out of ActionScript.
I've been trying for some period of time to make an if-else statement work with dynamic text. As far as can be determined, only two code blocks will work. Any numeric values will work in the two code blocks, but anything in the third or subsequent blocks returns the default, labeled "error."
I'm running Flash MX. According to Colin Moock's "ActionScript, the Definitive Guide," p. 134, I should be able to use an unlimited number of code blocks.
Appended below is the code. I tried to attach the *.fla file, but the forum said it was an unrecognized format! That's pretty bad if Macromedia's forum doesnt recognize the company's own file format! BTW, I had a bunch of problems getting on and using this forum.
BTW, among other things, I tried using double equal signs in the conditional -- no dice. Also, I included some other attempts -- switch statement and an an array push. Both gave identical results. Anyway, I'd be grateful if anyone could tell me how to fix this or at least why it won't work.
thanks, jay
/*For any given number for "value," the text will only properly display in the movie
if the number is within the first and second code blocks. Any number value within
the other code blocks returns as "error." It seems ridiculous that a conditional should
only work for two code blocks.*/
var value = 1.4
if (0.1 > value > 0) {
Info = "first";
} else if (1.5 > value > 0.1) {
Info = "second";
} else if (1.7 > value > 1.5) {
Info = "third";
} else if (3.0 > value > 1.7) {
Info = "fourth";
} else if (3.3 > value > 3.0) {
Info = "fifth";
} else if (4.6 > value > 3.3) {
Info = "sixth";
} else if (4.8 > value > 4.6) {
Info = "seventh";
} else if (6.2 > value > 4.8) {
Info = "eighth";
} else if (6.2 > value > 4.8) {
Info = "ninth";
} else {
Info = "error";
}
/*
Info = new Array();
Info.push(["first"]);
Info.push(["second"]);
Info.push(["third"]);
Info.push(["fourth"]);
Info.push(["fifth"]);
Info.push(["sixth"]);
Info.push(["seventh"]);
Info.push(["eighth"]);
Info.push(["ninth"]);
Info.push(["error"]);
if (0.1 > value > 0) {
Info = Info[0];
} else if (1.5 > value > 0.1) {
Info = Info[1];
} else if (1.7 > value > 1.5) {
Info = Info[2];
} else if (3.0 > value > 1.7) {
Info = Info[3];
} else if (3.3 > value > 3.0) {
Info = Info[4];
} else if (4.6 > value > 3.3) {
Info = Info[5];
} else if (4.8 > value > 4.6) {
Info = Info[6];
} else if (6.2 > value > 4.8) {
Info = Info[7];
}else if (value > 6.2) {
Info = Info[8];
} else {
Info = Info[9];
}
*/
/*
switch (value) {
case "(0.1 > value > 0)":
Info = "first";
break;
case "(1.47 > value > 0.1)":
Info = "second";
break;
case "(1.68 > value > 1.47)":
Info = "third";
break;
case "(3.03 > value > 1.68)":
Info = "fourth";
break;
case "(3.25 > value > 3.03)":
Info = "fifth";
break;
case "(4.60 > value > 3.25)":
Info = "sixth";
break;
case "(4.82 > value > 4.60)":
Info = "seventh";
break;
case "(6.17 > value > 4.82)":
Info = "eighth";
break;
case "(value > 6.17)":
Info = "ninth";
break;
default:
Info = "error";
}
*/
trace (value);
trace (Info);
jayfromcleveland webforumsuser@macromedia.com Guest
-
Problems with displaying dynamic Arabic text
We have a problem with a navigation system we are building which has to be able to display dynamic Arabic text. We are pulling in the Arabic text... -
Anti-aliased dynamic text problems
Hey all, my dynamicly loaded text wont anti-alias characters like "é" and "ü", they just dissappear from the text. I tried embedding font... -
Dynamic Text Problems with nested SWFs
I created a SWF that uses uses dynamic text to show song IDs for an MP3 player It works great by itself, but when I load this SWF as a movie into... -
load external text to dynamic text field in levels
Dear Sir I found the Tech Noe Index #16238 is useful in creating dynamically loaded text from external text file. However, the method mentioned... -
Dynamic text box within dynamic movie clip
I'm having a similar problem. On mine I noticed that although the text doesn't show and the border doesn't show, the cursor changes appropriately... -
Jeckyl #2
Re: Problems with if-else statements in dynamic text
you cannot use 0.1 > value > 0 etc ... it nonsense
Jeckyl Guest
-
jayfromcleveland webforumsuser@macromedia.com #3
Re: Problems with if-else statements in dynamic text
What do you mean "it nonsense" (sic)? It's a range of values, a perfectly acceptable mathematical expression, and a valid condition for a "true/false" determination. So how would you from select multiple values? Next time, why not write a helpful reply?
jayfromcleveland webforumsuser@macromedia.com Guest
-
domconlon webforumsuser@macromedia.com #4
Re: Problems with if-else statements in dynamic text
Flash works using the variable and then the value. So you can do the following:
if (myvar != 6 && myvar > 5) {
gotoAndPlay("label1");
}
but you can't do:
if (6 != myvar) {
gotoAndPlay("nochanceinhell");
}
hope this helps
Dom
domconlon webforumsuser@macromedia.com Guest
-
jayfromcleveland webforumsuser@macromedia.com #5
Re: Problems with if-else statements in dynamic text
Hi Dom, I see, so if I set this up as a compound conditional, Flash will know what to do since the variable will be presented first. I'll give that a try. Thanks! -jay
jayfromcleveland webforumsuser@macromedia.com Guest
-
Jeckyl #6
Re: Problems with if-else statements in dynamic text
its not really valid for a programming languages.
you can only do one comparison at a time.
mathematically you may write
a < b < c
to mean b is between a and c
in a programming language like AS, you would write
a < b && b < c
(ie a is less than b and b is less then c).
what you wrote is syntactically correct, but it doesn't do anything like
what you think it is doing !!!
Jeckyl Guest



Reply With Quote

