Tweenerライクに使いたい人向け。
デコレーターパターンが台無しなのでなんか代替案ほしいなあ。
import net.hires.utils.Stats;
addChild( new Stats() );
Progression 4
@author Copyright (C) 2007-2009 taka:nium.jp, All Rights Reserved.
@version 4.0.1 Public Beta 1.3
@see http://progression.jp/
Progression Software is released under the Progression Software License:
http://progression.jp/ja/overview/license
Progression Libraries is released under the MIT License:
http://www.opensource.org/licenses/mit-license.php
package jp.progression.commands.tweens {
<span lang="ja">コマンド処理中に状態が更新された場合に送出されます。</span>
<span lang="en"></span>
@eventType jp.progression.events.ExecuteEvent.EXECUTE_UPDATE
[Event( name="executeUpdate", type="jp.progression.events.ExecuteEvent" )]
<span lang="ja">DoTweener クラスは、caurina.transitions.Tweener パッケージのイージング機能を実行するコマンドクラスです。</span>
<span lang="en"></span>
@see http://code.google.com/p/tweener/
@see http://code.google.com/p/tweener/wiki/License
@example <listing version="3.0" >
DoTweener インスタンスを作成する
var c
/**
* Copyright yd_niku ( http://wonderfl.net/user/yd_niku )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/2WPf
*/
package {
// Tweenerライクに使いたい人向け。
// デコレーターパターンが台無しなのでなんか代替案ほしいなあ。
import flash.display.*;
import flash.events.*;
import jp.progression.commands.*;
import jp.progression.commands.lists.*;
import jp.progression.commands.tweens.*;
import org.libspark.betweenas3.easing.*;
// import net.hires.utils.Stats;
[SWF(frameRate=60)]
public class FlashTest extends Sprite {
private var canvas:Shape;
public function FlashTest() {
//addChild( new Stats() );
addChild( canvas = new Shape() );
canvas.graphics.beginFill(0xFF0000);
canvas.graphics.drawRect(-20,-20,40,40);
canvas.graphics.endFill();
var list:SerialList = new SerialList();
list.addCommand(
new Prop(canvas,{x:100, y:100, scaleX:0.8,scaleY:0.8,alpha:0}),
1,
new DoBetweenAS3(canvas,{scaleX:1, scaleY:1, alpha:1, time:1, transition:Back.easeOutWith(2)}),
new DoBetweenAS3(canvas,{x:400,y:400,time:5,transition:Circ.easeOut} ),
new DoBetweenAS3(canvas,{scaleX:3,scaleY:3,time:1,transition:Elastic.easeOut} ),
new DoBetweenAS3(canvas,{rotation:360,time:1,transition:Elastic.easeOut} ),
new DoBetweenAS3(canvas,{rotation:180, x:100, y:100, time:1,transition:Quart.easeInOut} ),
new DoBetweenAS3(canvas,{_blurFilter:{blurX: 24,blurY: 24}, alpha:0, time:1,transition:Sine.easeInOut} ),
"complete"
);
list.execute();
}
}
}
/**
* Progression 4
*
* @author Copyright (C) 2007-2009 taka:nium.jp, All Rights Reserved.
* @version 4.0.1 Public Beta 1.3
* @see http://progression.jp/
*
* Progression Software is released under the Progression Software License:
* http://progression.jp/ja/overview/license
*
* Progression Libraries is released under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
*/
//package jp.progression.commands.tweens {
import jp.nium.utils.ObjectUtil;
import jp.progression.commands.Command;
import jp.progression.events.ExecuteEvent;
import org.libspark.betweenas3.BetweenAS3;
import org.libspark.betweenas3.core.easing.IEasing;
import org.libspark.betweenas3.events.TweenEvent;
import org.libspark.betweenas3.tweens.IObjectTween;
/**
* <span lang="ja">コマンド処理中に状態が更新された場合に送出されます。</span>
* <span lang="en"></span>
*
* @eventType jp.progression.events.ExecuteEvent.EXECUTE_UPDATE
*/
//[Event( name="executeUpdate", type="jp.progression.events.ExecuteEvent" )]
/**
* <span lang="ja">DoTweener クラスは、caurina.transitions.Tweener パッケージのイージング機能を実行するコマンドクラスです。</span>
* <span lang="en"></span>
*
* @see http://code.google.com/p/tweener/
* @see http://code.google.com/p/tweener/wiki/License
*
* @example <listing version="3.0" >
* // DoTweener インスタンスを作成する
* var com:DoTweener = new DoTweener();
*
* // コマンドを実行する
* com.execute();
* </listing>
*/
//public class DoBetweenAS3 extends Command {
class DoBetweenAS3 extends Command {
/**
* <span lang="ja"></span>
* <span lang="en">Any object that will suffer a tweening. These objects are usually MovieClip, TextField, or Sound instances, or any other custom object with a numeric property that needs to be tweened.</span>
*/
public function get target():Object { return _target; }
public function set target( value:Object ):void { _target = value; }
private var _target:Object;
/**
* <span lang="ja"></span>
* <span lang="en">An object containing various properties of the original object that you want to tween on the original objects, with their final values assigned (some special properties are also allowed), as well as some built-in Tweener properties used when defining tweening parameters. This is like the recipe for the tweening, declaring both what will be tweened, and how.</span>
*/
public function get parameters():Object { return _parameters; }
public function set parameters( value:Object ):void { _parameters = value; }
private var _parameters:Object;
private var __parameters:Object;
private var _tween:IObjectTween;
private var _time:Number;
private var _easing:IEasing;
private var _originalParameters:Object;
/**
* <span lang="ja">新しい DoTweener インスタンスを作成します。</span>
* <span lang="en">Creates a new DoTweener object.</span>
*
* @param target
* <span lang="ja"></span>
* <span lang="en">Any object that will suffer a tweening. These objects are usually MovieClip, TextField, or Sound instances, or any other custom object with a numeric property that needs to be tweened.</span>
* @param tweeningParameters
* <span lang="ja"></span>
* <span lang="en">An object containing various properties of the original object that you want to tween on the original objects, with their final values assigned (some special properties are also allowed), as well as some built-in Tweener properties used when defining tweening parameters. This is like the recipe for the tweening, declaring both what will be tweened, and how.</span>
* @param initObject
* <span lang="ja">設定したいプロパティを含んだオブジェクトです。</span>
* <span lang="en"></span>
*/
public function DoBetweenAS3( target:Object, parameters:Object, initObject:Object = null ) {
// 引数を設定する
// target:Object, to:Object, time:Number = 1.0, easing:IEasing = null
_target = target;
_parameters = parameters || {};
_time = _parameters.time as Number || 0;
_easing = _parameters.transition as IEasing || null;
delete _parameters.time;
delete _parameters.transition;
// 親クラスを初期化する
super( _executeFunction, _interruptFunction, initObject );
// initObject が DoTweener であれば
var com:DoBetweenAS3 = initObject as DoBetweenAS3;
if ( com ) {
_time = com._time;
_easing = com._easing;
}
}
/**
* 実行されるコマンドの実装です。
*/
private function _executeFunction():void {
_tween = BetweenAS3.to( _target, _parameters, _time, _easing );
_tween.addEventListener(TweenEvent.UPDATE, _update );
_tween.addEventListener(TweenEvent.COMPLETE, _complete );
_tween.play();
}
/**
* 破棄します。
*/
private function _destroy():void {
// 破棄する
if(_tween) {
_tween.removeEventListener(TweenEvent.UPDATE, _update );
_tween.removeEventListener(TweenEvent.COMPLETE, _complete );
}
_tween = null;
}
/**
*
*/
private function _complete(e:TweenEvent):void {
// 破棄する
_destroy();
// 処理を終了する
super.executeComplete();
}
/**
*
*/
private function _update(e:TweenEvent):void {
// イベントを送出する
super.dispatchEvent( new ExecuteEvent( ExecuteEvent.EXECUTE_UPDATE, false, false, this ) );
}
/**
*
*/
private function _error( errorScope:Object, metaError:Error ):void {
errorScope;
// 破棄する
_destroy();
// 例外をスローする
super.throwError( this, metaError );
}
/**
* 中断実行されるコマンドの実装です。
*/
private function _interruptFunction():void {
// 中断する
try {
_tween.stop();
}
catch ( e:Error ) {}
// 中断方法によって処理を振り分ける
switch ( super.interruptType ) {
case 0 : { _tween.gotoAndStop(0); break; }
case 2 : { _tween.gotoAndStop(1); break; }
}
// 破棄する
_destroy();
}
/**
* <span lang="ja">DoTweener インスタンスのコピーを作成して、各プロパティの値を元のプロパティの値と一致するように設定します。</span>
* <span lang="en">Duplicates an instance of an DoTweener subclass.</span>
*
* @return
* <span lang="ja">元のオブジェクトと同じプロパティ値を含む新しい DoTweener インスタンスです。</span>
* <span lang="en">A new DoTweener object that is identical to the original.</span>
*/
override public function clone():Command {
return new DoBetweenAS3( _target, _parameters, this );
}
/**
* <span lang="ja">指定されたオブジェクトのストリング表現を返します。</span>
* <span lang="en">Returns the string representation of the specified object.</span>
*
* @return
* <span lang="ja">オブジェクトのストリング表現です。</span>
* <span lang="en">A string representation of the object.</span>
*/
override public function toString():String {
return ObjectUtil.formatToString( this, super.className, super.id ? "id" : null, "target" );
}
}
//}