I know this is probably an easy thing to do but I am really struggling with AS3 and would be infinitely grateful if someone could clear the fog from my brain. I’ve been working on this since yesterday…
The goal is to have the user enter their name in the input text box and then click start. When they click start a ball starts rolling and a welcome message should display “Welcome + name”.
At first the ball is rolling fine and the name is displayed - but after about 3 seconds the frames sort of flip and “Welcome name” turns into just “Welcome” (name dissapears)
I’m sure it’s something really dumb but my eyes are crossing.
- layer 1 is my circle image (myCircle)
- layer 2 is my button (startButton)
- layer 3 is the input field (inputName) and the dynamic field (displayName)
Here’s the code:
stop();
var inputName:TextField = new TextField();
inputName.type = TextFieldType.INPUT;
inputName.x=200;
inputName.y=100;
inputName.width=150;
inputName.height=20;
inputName.border = true;
addChild(inputName);
// add an event listener to our button:
startButton.addEventListener(MouseEvent.CLICK, startButtonHandler);
// deal with the event when the button is clicked:
function startButtonHandler (evt:MouseEvent) {
myCircle.x = 50;
myCircle.y = 300;
gotoAndPlay(2);
moveCircle(); // add event listener to circle
}
// when the button is clicked, add an event listener to the circle
function moveCircle () {
myCircle.addEventListener (Event.ENTER_FRAME, goCircle);
}
// once event listener is added, move the circle ever frame
function goCircle (evt:Event) {
myCircle.x = myCircle.x+1;
displayName.text = "Welcome " + inputName.text;
}
Thanks sooooo much for you input