A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: AS2 Node values vary

  1. #1
    Member
    Join Date
    May 2008
    Posts
    70

    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?

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    Why did you have to convert the variable stage_status to String?

    Anyway, an if/else if/else or switch(case) could work.

    gparis

  3. #3
    Member
    Join Date
    May 2008
    Posts
    70
    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);
    }

  4. #4
    Member
    Join Date
    May 2008
    Posts
    70
    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") {

  5. #5
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    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

  6. #6
    Member
    Join Date
    May 2008
    Posts
    70
    Thanks gparis thats a great help, incidentally, how would you do it without convert to string?

  7. #7
    Member
    Join Date
    May 2008
    Posts
    70
    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

  8. #8
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center