-
AS2 Node values vary
Hi, The code below works but now I have the problem that the node value has three possible images to load. Numbers from:
1-7 needs to load image1.png
8-127 needs to load image2.png
128-500 needs to load image3.png
if(stage_status.toString()=="128") {
loadMovie(_root.content_folder_path+"images/image3", holder_status);
}
Does anyone know how I can get this working please?
-
Why did you have to convert the variable stage_status to String?
Anyway, an if/else if/else or switch(case) could work.
gparis
-
Sorry, I didn't explain that very well. The number comes from an xml node, the code is
for(h=0; h<Header_Data_xml.childNodes.length; h++)
if(Header_Data_xml.childNodes[h].nodeName == "n_PhaseStatusCode")
stage_status = Header_Data_xml.childNodes[h].firstChild;
if(stage_status.toString()=="128") {
loadMovie(_root.content_folder_path+"images/image1.png", holder_status);
}
-
Would I have to do an 'if' for each number or is there a way of saying all numbers from 8 to127
if(stage_status.toString()=="8-127") {
-
i still don't know why you would have to convert to String but this time you should do the contrary. The 'number' coming from xml must arrive already as a String. You'll need to convert to Number to do calculations.
So, something in these lines:
if(Number(stage_status) > 0 && Number(stage_status) < 8) in other words if it's between 1 and 7, etc.
gparis
-
Thanks gparis thats a great help, incidentally, how would you do it without convert to string?
-
Hi gparis,I tried it but it doesn't work, any idea why?
for(h=0; h<Header_Data_xml.childNodes.length; h++)
if(Header_Data_xml.childNodes[h].nodeName == "n_PhaseStatusCode")
stage_status = Header_Data_xml.childNodes[h].firstChild;
if(Number(stage_status) > 0 && Number(stage_status) < 8)
loadMovie(_root.content_folder_path+"images/b4start.png", holder_status);
if(Number(stage_status) > 7 && Number(stage_status) < 128)
loadMovie(_root.content_folder_path+"images/started.png", holder_status);
if(Number(stage_status) > 127 && Number(stage_status) < 500)
loadMovie(_root.content_folder_path+"images/finished.png", holder_status);
Thank you for your time I really appreciate it
-
For debugging purposes, add traces:
Actionscript Code:
stage_status = Header_Data_xml.childNodes[h].firstChild; trace(stage_status); trace(_root.content_folder_path+"images/b4start.png");
You could also add traces after the ifs see if the conditions are met.
By the way instead of if/if/if, use if/else if/else, as i first suggested.
gparis
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
|