String - If else not functioning!?
hi
I've got the following code, I am trying to appendText to the same text Field (instance name = info). Problem is it seems to be ignoring the if statements and just outputs the last else string only.
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.MouseEvent;
import flash.display.Sprite
crabBtn.addEventListener(MouseEvent.CLICK, ldr1);
kidsBtn.addEventListener(MouseEvent.CLICK, ldr5);
// Function to handle mouse event, and the void means its not returning any value.
function ldr1(Event:MouseEvent):void {
crabLdr.ldrCrab.source="./images/crabMov.swf";
// Converting the text fields content into a string which is called myString
var myString:String = info.text;
/* This will show text enclosed in the "", and if there is any other text before it, it will be added to it.*/
if(myString == "Good Morning! We are Andy and Stacy "){
info.appendText("and I am Ralph the crab!");
} else if(myString == "Good Morning! We are Andy and Stacy "){
info.appendText("and I am Ralph the crab!");
} else {
info.appendText("Hello, I am Ralph. Let's have some fun together at the beach. ");
}
}
function ldr5(Event:MouseEvent):void {
kidsLdr.ldrKids.source="./images/KidsMov.swf";
var myString:String = info.text;
if (myString == "Hello, I am Ralph. Let's have some fun together at the beach."){
info.appendText("We will build a big sand castle together.");
} else if (myString == "whatever"){
info.appendText("whatever");
} else {
info.appendText("Good Morning! We are Andy and Stacy ");
}
}
Any tips please as to why its not working please?
Thanks ![]()