PDA

View Full Version : If else query...


AliHurworth
01-02-2010, 04:02 PM
Hi all,
This must be simple query, but I'm struggling to get this to work...

All I want to happen is for the textArea to 1)evaluate which option has been chosen in the combobox, and 2) show an appropriate message.

This is the code I have. I can't seem to create an "OR" function,i.e.
...if (entry.text=="Head"¦¦"Arms") {...

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import flash.events.Event;
private function showBodyPart(event:Event):void {
if (entry.text=="Head") {
textArea.text="Inna de ed";
} else if (entry.text=="Chest"){
textArea.text=="Somewhere else";
} else
textArea.text=="A third place";
}
]]>
</mx:Script>
<mx:ComboBox x="97" y="86" id="entry" text="Enter the Body Part" change="showBodyPart(event)">
<mx:ArrayCollection>
<mx:String>Head</mx:String>
<mx:String>Arms</mx:String>
<mx:String>Chest</mx:String>
<mx:String>Abdomen</mx:String>
<mx:String>Legs</mx:String>
</mx:ArrayCollection>
</mx:ComboBox>
<mx:TextArea x="97" y="127" id="textArea" text="Select a body part above" editable="false"/>



</mx:Application>

bowljoman
01-02-2010, 04:25 PM
(entry.text=="Head" || entry.text== "Arms")

AliHurworth
01-02-2010, 10:35 PM
Thanks Bowljoman.

This is what worked ("=" vs "==")

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import flash.events.Event;
private function showBodyPart(event:Event):void {
if (entry.text=="Head") {
textArea.text="Head";
} else if (entry.text=="Chest"||entry.text=="Arms"){
textArea.text="Top half";
} else if (entry.text=="Abdomen"||entry.text=="Legs"){
textArea.text="Lower half";
}
else {
textArea.text="Error!";
}
}
]]>
</mx:Script>
<mx:ComboBox x="97" y="86" id="entry" text="Enter the Body Part" change="showBodyPart(event)">
<mx:ArrayCollection>
<mx:String>Head</mx:String>
<mx:String>Arms</mx:String>
<mx:String>Chest</mx:String>
<mx:String>Abdomen</mx:String>
<mx:String>Legs</mx:String>
</mx:ArrayCollection>
</mx:ComboBox>
<mx:TextArea x="97" y="127" id="textArea" text="Select a body part above" editable="false"/>



</mx:Application>