Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

24.1. No Loops

To create animation with ActionScript, we change visual content repeatedly over time, producing the illusion of movement. For example, to animate a TextField object horizontally across the screen, we would repeatedly increase, or decrease, its instance variable x. In some programming languages, the natural mechanism for repeatedly altering an instance variable is a loop statement. Consequently, programmers who are new to ActionScript might expect to create animation using a while loop, such as the one shown in the following code:

public class TextAnimation extends Sprite {
  public function TextAnimation () {
    // Create a TextField
    var t:TextField = new TextField();
    t.text          = "Hello";
    t.autoSize      = TextFieldAutoSize.LEFT;
    addChild(t);

    // Update the TextField's horizontal position repeatedly, and stop
					    // when it reaches x-coordinate 300
					    while (t.x <= 300) {
					      t.x += 10;
					    }
  }
}


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial