In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: STAR WARS opening crawl

// forked from undo's STAR WARS opening crawl
package

    
    import flash.display.*;
    import flash.events.Event;
    import flash.events.FocusEvent;
    import flash.geom.PerspectiveProjection;
    import flash.geom.Point;
    import flash.text.TextField;
    import flash.text.TextFieldType;
    import flash.text.TextFormat;
    
    [SWF(backgroundColor=0x000000,frameRate=60)]
    public class ASTest extends Sprite
    {
        
        private var _input:TextField;
        private var _output:TextField;
        private var _primitive:Sprite;
        
        public function ASTest()
        {
            addEventListener(Event.ADDED_TO_STAGE, init);
        }
        private function init(evt:Event = null):void
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            
            var pp:PerspectiveProjection = this.transform.perspectiveProjection;
            pp.projectionCenter = new Point(stage.stageWidth/2, 0);
            
            
            var backGround:Sprite = addChild(new Sprite()) as Sprite;
            backGround.graphics.beginFill(0x0);
            backGround.graphics.drawRect(0,0,stage.stageWidth, stage.stageHeight);
            backGround.graphics.endFill();
            for(var i:int = 0; i < 100; i++)
            {
                var star:Sprite = backGround.addChild(new Sprite()) as Sprite;
                star.graphics.beginFill(0xffffff, Math.random()*0.5+0.5);
                star.graphics.drawCircle(0,0,Math.random()*1+1);
                star.graphics.endFill();
                star.x = Math.random()*stage.stageWidth;
                star.y = Math.random()*stage.stageHeight;
            }
            
            _primitive = addChild(new Sprite()) as Sprite;
            _output = _primitive.addChild(new TextField()) as TextField;
            _input = addChild(new TextField()) as TextField;
            
            _input.type = TextFieldType.INPUT;
            _input.background = true;
            _input.border = true;
            _input.wordWrap = true;
            _input.multiline = true;
            //_input.text = 'It is a period of civil war. Rebel spaceships, striking from a hidden base, have won their first victory against the evil Galactic Empire. During the battle, Rebel spies managed to steal secret plans to the Empire’s ultimate weapon, the DEATH STAR, an armored space station with enough power to destroy an entire planet. Pursued by the Empire’s sinister agents, Princess Leia races home aboard her starship, custodian of the stolen plans that can save her people and restore freedom to the galaxy...';
            _input.text = '';
            _input.width = stage.stageWidth-20;
            _input.x = 10;
            _input.y = 10;
            _input.alpha = 0.2;
            _input.addEventListener(FocusEvent.FOCUS_IN, onFocusIn);
            _input.addEventListener(FocusEvent.FOCUS_OUT, onFocusOut);
            _input.addEventListener(Event.CHANGE, onChange);
            
            var tf:TextFormat = new TextFormat('_sans', 24, 0xEAC968);
            _output.defaultTextFormat = tf;
            _output.wordWrap = true;
            _output.multiline = true;
            _output.width = stage.stageWidth/2;
            _output.x = -_output.width/2;
            _output.selectable = false;
            
            _primitive.rotationX = -90;
            _primitive.x = stage.stageWidth/2;
            _primitive.y = stage.stageHeight/2;
            _primitive.z = -Math.sqrt(stage.stageHeight)*10;
            _primitive.mouseEnabled = _primitive.mouseChildren = false;
            
            onChange();
            
            addEventListener(Event.ENTER_FRAME, onEnter);
        }
        
        private function onFocusIn(evt:FocusEvent):void
        {
            _input.alpha = 1;
        }
        private function onFocusOut(evt:FocusEvent):void
        {
            _input.alpha = 0.2;
        }
        private function onChange(evt:Event=null):void
        {
            _output.text = _input.text;
            _output.height = _output.textHeight + 10;
            _primitive.z = -Math.sqrt(stage.stageHeight)*10;
        }
        
        private function onEnter(evt:Event):void
        {
            _primitive.z += 0.4;
        }
        
    }
}