Search code examples
flashif-statementactionscript-2

if else statement in as2


I have a flash file in witch I"m receiving data from XML document and need when specific word is shown to load a picture. For example I have:

 if (_root.main.ma4.team1.text = "specific text") 
     {
       _root.main.ma4.testo.text = "works";
    }else{
       _root.main.ma4.testo.text = "notworks";
    }

So I'm getting "specific text" from the XML file, but right now it's always show me "works" doesn't matter what kind of text i'm getting from the XML. Only shows me notworks when there is no text in the field. So i need to show me "works"only when the specific text is shown.


Solution

  • you should use == instead of = when comparing :

    if (_root.main.ma4.team1.text == "specific text") 
         {
            _root.main.ma4.testo.text = "works";
         }
    else {
            _root.main.ma4.testo.text = "notworks";
         }
    

    and instead of : my_xml.firstChild.childNodes[2].firstChild;

    use : my_xml.firstChild.childNodes[2].nodeValue