topical media & game development

talk show tell print

#graphic-flex-image-effects-06-Flex-ScrollingText.ax

#graphic-flex-image-effects-06-Flex-ScrollingText.ax [swf] [flash] flex


  package {
  
          import flash.display.Sprite;
          import flash.events.Event;
          import flash.text.TextField;
          import flash.text.TextFieldAutoSize;
          import flash.text.TextFormat;
          import flash.text.TextFormatAlign;
  
          [SWF(width=800, height=600, backgroundColor=0x000000)]
  
          
Rotates text in 3D space then animates it a la the Star Wars opening titles.

  
          public class @ax-graphic-flex-image-effects-06-Flex-ScrollingText extends Sprite {
  
                  private var _textfield:TextField;
  
                  
Constructor. Creates and rotates text, then sets up listener for ENTER_FRAME to handle animating the text.

  
                  public function @ax-graphic-flex-image-effects-06-Flex-ScrollingText() {
                          _textfield = new TextField();
                          _textfield.width = stage.stageWidth/2;
                          _textfield.selectable = false;
                          _textfield.autoSize = TextFieldAutoSize.LEFT;
                          _textfield.multiline = true;
                          _textfield.wordWrap = true;
                          // make sure to use different font if Impact is not installed
                          var format:TextFormat = new TextFormat("Impact", 40, 0xFFFFFF);
                          format.align = TextFormatAlign.JUSTIFY;
                          _textfield.defaultTextFormat = format;
                          _textfield.text = "This is a simple example of scrolling text like you might find at the beginning of a movie that came out a long time ago in a galaxy exactly like this one. . .";
                          // place text in bottom third of stage
                          _textfield.y = stage.stageHeight/3;
  
                          // the holder is what is positioned in 3D space so that
                          // text can scroll on single axis and the perspective
                          // can more easily be maintained
                          var textHolder:Sprite = new Sprite();
                          textHolder.x = stage.stageWidth/2 - _textfield.width/2;
                          textHolder.y = stage.stageHeight/2;
                          textHolder.z = -200;
                          textHolder.rotationX = -60;
                          textHolder.addChild(_textfield);
                          addChild(textHolder);
  
                          addEventListener(Event.ENTER_FRAME, onSpriteEnterFrame);
                  }
  
                  
Handler for ENTER_FRAME event, moves textfield up y axis.
parameter: event Event dispatched by this sprite.

  
                  private function onSpriteEnterFrame(event:Event):void {
                          _textfield.y -= 1;
                  }
  
          }
  
  }


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.