flash on 2009-9-19

by esukei
♥0 | Line 57 | Modified 2009-10-16 00:28:12 | MIT License
play

ActionScript3 source code

/**
 * Copyright esukei ( http://wonderfl.net/user/esukei )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/2QUN
 */

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.geom.Point;
    [SWF(frameRate = "8")]
    public class FlashTest extends Sprite {
        
        private var textField:TextField;
        private var a:Point;
        private var v:Point;
        private var p:Point;
        private var da:Point;
        private var dv:Point;
        private var dp:Point;        
        
        public function FlashTest() {
            // write as3 code here..
            textField = new TextField();
            textField.width = stage.stageWidth;
            textField.height = 100;
            textField.y = stage.stageHeight - textField.height;
            textField.multiline = true;
            textField.text = 'LOGGING HERE.';
            addChild(textField);
            
            a = new Point(0,0);
            v = new Point(0,0);
            p = new Point(0,0);
            
            da = new Point(0,0);
            dv = new Point(0,0);
            dp = new Point(0,0);
            
            addEventListener(Event.ENTER_FRAME, calc);
            
        }
        
        private function calc(e:Event):void
        {
            clearLog();

            
            a.x = (stage.mouseX - p.x) - v.x;
            a.y = (stage.mouseY - p.y) - v.y;
            
            v.x += a.x;
            v.y += a.y;
            
            p.x += v.x;
            p.y += v.y;
            
            addLog('a-x: ' + a.x.toString());
            addLog('a-y: ' + a.y.toString());
            addLog('v-x: ' + v.x.toString());
            addLog('v-y: ' + v.y.toString());
            addLog('p-x: ' + p.x.toString());
            addLog('p-y: ' + p.y.toString());
        }
        
        private function addLog(log:String):void
        {
            textField.appendText(log + '\n');
        }
        
        private function clearLog():void
        {
            textField.text = '';
        }
        
    }
}