Task: Word Animation

I l @ ve RuBoard

In this example, the entire Flash movie is one large text field that displays a message one word at a time. It gets the words from a sentence defined in ActionScript and changes to the next word every so many frames .

  1. Start with a blank Flash movie.

  2. Create a dynamic text field. Use a large font, such as 64 point. Place it in the middle of the screen and set the alignment of the text so that it is centered. Link this text field to the variable text .

  3. Create a small movie clip by drawing a shape and then choosing Insert, Convert to Movie Clip. Name the instance of this movie clip Actions. Move the movie clip outside the visible area.

  4. Place the following script on the movie clip. It starts off by using split to divide a sentence into an array of words. It then sets three other variables . The wordNum variable is which word is to be displayed next. The frameDelay variable is the number of frames that need to pass until the word changes. The frameCount variable keeps track of the frames as they go by.

     onClipEvent(load) {     // get the words     wordList = ("Imagination is more important than knowledge").split(" ");     // set up variables     wordNum = 0;     frameDelay = 6;     frameCount = frameDelay; // prime for first word } 

    The enterFrame handler checks to see whether frameCount equals frameDelay . If they are equal, it is time for another word. The new word is placed in the text field, which is at the root level. Then wordNum is increased to prepare for the next word. If there are no more words, then wordNum is set back to 0. The handler ends by increasing frameCount by 1, which it does every frame.

     onClipEvent(enterFrame) {     // time for new word     if (frameCount == frameDelay) {         _root.text = wordList[wordNum]; // display word         wordNum++; // next word         if (wordNum >= wordList.length) wordNum = 0;         frameCount = 0;     }     frameCount++; } 
  5. Test your movie or look at 11wordserver.fla. You can color up the movie with some background elements. The example has a short message, but this type of movie could be an effective introduction to a larger presentation.

I l @ ve RuBoard

Sams Teach Yourself Flash MX ActionScript in 24 Hours
Sams Teach Yourself Flash MX ActionScript in 24 Hours
ISBN: 0672323850
EAN: 2147483647
Year: 2002
Pages: 272

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net