A Flash Developer Resource Site

Results 1 to 1 of 1

Thread: as2 xml value changes mc color

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    1

    as2 xml value changes mc color

    Hi, I am not a coder so I got stuck with this as2 code.
    I have 3 movieclips named loc1, loc2, loc3 and I wanted them to change into 3 colors depending on number from xml file (numbers from 1-100). Now I don't get any errors but I am sure I messed up this code, and I am not sure if XML has the right structure. I can't find nothing similar in tutorials so I am humbly asking for a help. Thanks!

    AS2..............................
    PHP Code:
    var dots:XML = new XML();
    dots.ignoreWhite=true
    dots.load('data.xml');  

    xmlLoaded = function(success){

    if(
    success){
    var 
    myColor1:Color = new Color("loc1");
    var 
    myColor2:Color = new Color("loc2");
    var 
    myColor3:Color = new Color("loc3");
    // your color codes here
    if(dotsNode >= 90){
     
    myColor1.setRGB(0x00ff00);
      
    myColor2.setRGB(0x00ff00);
       
    myColor3.setRGB(0x00ff00);
     }
    if(
    dotsNode <= 89){

    myColor1.setRGB(0xffff00);
      
    myColor2.setRGB(0xffff00);
       
    myColor3.setRGB(0xffff00);
    }

    if(
    dotsNode <= 70){

    myColor1.setRGB(0xff0000);
      
    myColor2.setRGB(0xff0000);
       
    myColor3.setRGB(0xff0000);
    }
    } else {
    trace("Could not load XML");
    }
    }
    var 
    dots:XML = new XML();
    dots.ignoreWhite=true;
    dots.onLoad=xmlLoaded(); 
    dots.load('data.xml');  
    xmlLoaded = function(success){

    if(
    success){
    var 
    myColor1:Color = new Color("loc1");
    var 
    myColor2:Color = new Color("loc2");
    var 
    myColor3:Color = new Color("loc3");

    if(
    dotsNode >= 90){
     
    myColor1.setRGB(0x00ff00);
      
    myColor2.setRGB(0x00ff00);
       
    myColor3.setRGB(0x00ff00);
     }
    if(
    dotsNode <= 89){

    myColor1.setRGB(0xffff00);
      
    myColor2.setRGB(0xffff00);
       
    myColor3.setRGB(0xffff00);
    }

    if(
    dotsNode <= 70){

    myColor1.setRGB(0xff0000);
      
    myColor2.setRGB(0xff0000);
       
    myColor3.setRGB(0xff0000);
    }

    //etc...
    } else {
    trace("Could not load XML");
    }
    }

    var 
    dots:XML = new XML();
    dots.ignoreWhite=true;
    dots.onLoad=xmlLoaded();
    dots.load('data.xml');
    //dotsNode = this.childNodes[0].nodeValue;
    myColor1 parseInt(this.firstChild.childNodes[0].firstChild);
    myColor2 parseInt(this.firstChild.childNodes[1].firstChild);
    myColor3 parseInt(this.firstChild.childNodes[2].firstChild);
    myColor1 = new Color(loc1);
    myColor2 = new Color(loc2);
    myColor3 = new Color(loc3); 
    XML.............
    PHP Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <dots>
        <loc1>99</loc1>
        <loc2>77</loc2>
        <loc3>44</loc3>
     
    </dots>

    EDITED: I got it (after a long struggle). This post can be deleted.
    :
    :
    ")
    Last edited by gojakv; 09-28-2011 at 07:16 AM.

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