-
[F8] Weird "if" statement bug.
Hello -
I'm working on a flash piece using this code:
Code:
on (release) {
doorsSelected = "2";
if (dimensionsWidth<="60" && project == "closetdoors") {
gotoAndStop("project");
loadMovie(project+doorsSelected+"narrow.swf", "mcProject");
} else if (dimensionsWidth>"60" && project == "closetdoors") {
gotoAndStop("project");
loadMovie(project+doorsSelected+"wide.swf", "mcProject");
} else {
projectSelected();
}
trace(dimensionsWidth);
}
So a value of 60 or lower plays the "narrow" swf, 61 or higher plays the "wide" swf. It works fine until the value for "dimensionsWidth" is a 3-digit number, then it goes to the "narrow" swf when it should be going to the "wide" swf. If I type in 120, the output gives me 120.
Any ideas?
Thanks.
-
OOP is one letter from OOPS
is dimensionsWidth supposed to be a numeric value? If so, remove the quote marks from around the value as in:
dimensionsWidth<=60
-
Same issue. Thanks, though. Any other ideas?
-
OOP is one letter from OOPS
Where is dimensionsWidth set and can you post the updated code.
-
Code:
on (release) {
doorsSelected = "2";
if (dimensionsWidth<=60 && project == "closetdoors"
)
{
gotoAndStop("project");
loadMovie(project+doorsSelected+"narrow.swf", "mcProject");
} else if (dimensionsWidth>=60 && project == "closetdoors"
) {
gotoAndStop("project");
loadMovie(project+doorsSelected+"wide.swf", "mcProject");
} else {
projectSelected();
}
trace(dimensionsWidth);
}
"dimensionsWidth" is a dynamic text field in a previous frame. The trace shows the correct output.
-
OOP is one letter from OOPS
try using parseInt(dimensionsWidth)
on (release) {
doorsSelected = "2";
dimensionsWidth = parseInt(dimensionsWidth)
if (dimensionsWidth<=60 && project == "closetdoors"
)
{
gotoAndStop("project");
loadMovie(project+doorsSelected+"narrow.swf", "mcProject");
} else if (dimensionsWidth>=60 && project == "closetdoors"
) {
gotoAndStop("project");
loadMovie(project+doorsSelected+"wide.swf", "mcProject");
} else {
projectSelected();
}
trace(dimensionsWidth);
}
-
Awesome, that worked! Thanks!
What does that mean? Parse Integer? Was Flash not always recognizing it as a number?
This was my final code:
Code:
on (release) {
doorsSelected = "2";
dimensionsWidth = parseInt(dimensionsWidth)
if (dimensionsWidth<60 && project == "wallslidedoors") {
gotoAndStop("project");
loadMovie(project+doorsSelected+"narrow.swf", "mcProject");
} else if (project == "wallslidedoors") {
gotoAndStop("project");
loadMovie(project+doorsSelected+"wide.swf", "mcProject");
} else {
projectSelected();
}
}
-
OOP is one letter from OOPS
Because you are getting the value from a text field, the value is by default a string. Yes it means parse integer (convert string to number). So basically what used to be happening is you were comparing if one string was longer than another, hence a 3 digit string was always greater than a a two digit string and the greater than clause would run.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|