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

DoAnimation

hello 2009!!
Get Adobe Flash player
by northprint 12 Jan 2009
// write as3 code here..
//hello 2009!!
package {
    import flash.display.*;
    import flash.events.Event
    import jp.progression.commands.*;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.system.Security;

    [SWF(backgroundColor="#000000")]

    public class CreateCow extends MovieClip{  

        private var _loader:URLLoader;
        private var _sp:Sprite;

        public function CreateCow(){

            _sp= new Sprite();
            _sp.graphics.beginFill(0xff0000);
            _sp.graphics.drawCircle(0, 0, 5);
            _sp.graphics.endFill();

            Security.loadPolicyFile("http://narayama.heteml.jp/crossdomain.xml");
            _loader = new URLLoader();
            _loader.addEventListener(Event.COMPLETE,LoadHandler);
            _loader.load(new URLRequest("http://narayama.heteml.jp/test/cow.xml"));
        }
        private function LoadHandler(e:Event):void{
            var sList:SerialList = new SerialList();
            sList.addCommand(
                new AddChild(this, _sp),
                new DoAnimation(this, new XML(e.target.data), _sp, true),
                new RemoveChild(this, _sp)
            );
            sList.execute();
        }
    }
}

    import flash.display.DisplayObject;
    import flash.display.DisplayObjectContainer;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.geom.Point;
    import jp.progression.commands.*;
    import jp.progression.core.commands.Command;

    class DoAnimation extends Command {
		
	private var _motionXml:XML;
	private var _moveObject:DisplayObject;
	private var _waitForComplete:Boolean;
	private var _keyframeCount:int = 0;
	private var _keyframeLength:int = 0;
	private var _canvas:Sprite = new Sprite();
	private var _container:DisplayObjectContainer;
	private var _startPoint:Point;
	private var _ns:Namespace;
		
	/*======================================================================*//**
	 * コンストラクタ
	 */
	public function DoAnimation(container:DisplayObjectContainer, motionXml:XML, moveObject:DisplayObject, waitForComplete:Boolean = false, initObject:Object = null ) {
	    super( _execute, _interrupt, initObject );
	    _motionXml = motionXml;
	    _container = container;
	    _moveObject = moveObject;
	    _waitForComplete = waitForComplete;
	}
		
	private function parseXML(xml:XML = null):void {
	    _ns = new Namespace("fl.motion.*");	
	    _startPoint = new Point();
	    _startPoint.x = xml._ns::source._ns::Source.@x;							
	    _startPoint.y = xml._ns::source._ns::Source.@y;					
	    _moveObject.x = _startPoint.x;
	    _moveObject.y = _startPoint.y;
	    _keyframeLength = int(xml.@duration);
	}	
		
        private function _execute():void {
            timeOut = 0;
            //xmlパース
            parseXML(_motionXml);
            _container.addChild(_canvas);	
            _canvas.graphics.lineStyle(2, 0x0000ff);
            _canvas.graphics.moveTo(_moveObject.x, _moveObject.y);	
            //EnterFlame
            _keyframeCount = 1;
            _moveObject.addEventListener(Event.ENTER_FRAME, EnterframeHandler);	
            // 通常処理を終了します。
            if (_waitForComplete == false) {
                executeComplete();
            }
        }		
        
        private function EnterframeHandler(e:Event):void {	
            _keyframeCount ++;	
            var newPoint:Point = new Point();
            newPoint.x = Number(_motionXml._ns::Keyframe[_keyframeCount].@x);
            newPoint.y = Number(_motionXml._ns::Keyframe[_keyframeCount].@y);				
            if (newPoint.x!=0){
                _moveObject.x = _startPoint.x + newPoint.x;
            }
            if (newPoint.y!=0){
                _moveObject.y = _startPoint.y + newPoint.y;
            }
            _canvas.graphics.lineTo(_moveObject.x, _moveObject.y);			
            if (_keyframeCount == (_keyframeLength - 1)) {
                _moveObject.removeEventListener(Event.ENTER_FRAME, EnterframeHandler);
                if (_waitForComplete) {
                    executeComplete();
                }
            }
       }
	
        /*======================================================================*//**
         * 中断実行されるコマンドの実装です。
         */
        private function _interrupt():void {
            if (_keyframeCount > 1) {
                _moveObject.removeEventListener(Event.ENTER_FRAME, EnterframeHandler);
            }
            // 中断処理を終了します。
            interruptComplete();
        }
		
        /*======================================================================*//**
         * MyCommand インスタンスのコピーを作成して、各プロパティの値を元のプロパティの値と一致するように設定します。
         */
        public override function clone():Command {
            return new DoAnimation( _container, _motionXml, _moveObject, _waitForComplete, this );
        }
	}