
Animation is integral to many parts of GUIs, including both the fancy effects when things change used in window managers, and of course games.   The core of any animation system is a scheme for periodically changing the display while still remaining responsive to the user.   This task demonstrates this.



Task

Create a window containing the string "Hello World! " (the trailing space is significant).

Make the text appear to be rotating right by periodically removing one letter from the end of the string and attaching it to the front.

When the user clicks on the (windowed) text, it should reverse its direction.




//create the text box
var textBox:TextField = new TextField();
addChild(textBox);
 
var text = "Hello, World! ";
var goingRight = true;
 
//modify the string and update it in the text box
function animate(e:Event)
{
	if(goingRight)
		text = text.slice(text.length-1,text.length) + text.slice(0, text.length - 1);
	else
		text = text.slice(1) + text.slice(0,1);
	textBox.text = text;
}
 
//event handler to perform the animation
textBox.addEventListener(Event.ENTER_FRAME, animate);
//event handler to register clicks
textBox.addEventListener(MouseEvent.MOUSE_DOWN, function(){goingRight = !goingRight;});
 