Home > ActionScript | Progression > ProcessEvent イベントフローについて(2)

ProcessEvent イベントフローについて(2)

前回のままだと、特殊な使い方すぎてイベントフローの検証になってないので、ユーザーイベントでの遷移に変更して検証。

前回のクラスに移動用ボタンを設置したIndexクラスを作成します。

package
{
	import jp.progression.casts.CastButton;
	import jp.progression.casts.CastDocument;
	import jp.progression.commands.AddChild;
	import jp.progression.commands.Goto;
	import jp.progression.commands.RemoveChild;
	import jp.progression.commands.Trace;
	import jp.progression.Progression;
	import jp.progression.scenes.SceneId;
	import jp.progression.scenes.SceneObject;

	public class Index extends CastDocument
	{
		public var prog:Progression;

		public function Index()
		{

		}

		protected override function _onInit():void
		{
			prog = new Progression( "index", stage );

			prog.onProcessStart     = function() { trace( "onProcessStart :" + prog.eventType ); }
			prog.onProcessScene     = function() { trace( "onProcessScene :" + prog.eventType ); }
			prog.onProcessComplete  = function() { trace( "onProcessComplete :" + prog.eventType + "\n------" ); }
			prog.onProcessEvent     = function() { trace( "onProcessEvent :" + prog.eventType ); }
			prog.onProcessError     = function() { trace( "onProcessError :" + prog.eventType ); }
			prog.onProcessInterrupt = function() { trace( "onProcessInterrupt :" + prog.eventType + "\n------" ); }

			var b1:CastButton = new CastButton();
			b1.graphics.beginFill( 0xFF0000 );
			b1.graphics.drawRect( 0, 0, 100, 100 );
			b1.sceneId = new SceneId( "/index/scene2" );

			var b2:CastButton = new CastButton();
			b2.graphics.beginFill( 0x0000FF );
			b2.graphics.drawRect( 0, 0, 100, 100 );
			b2.sceneId = new SceneId( "/index/scene3" );

			prog.root.addScene( new SceneObject( "scene1", {
				onLoad: function():void {
					this.addCommand(
						new Trace( "scene1 : onLoad" )
					);
				},
				onInit: function():void {
					this.addCommand(
						new Trace( "scene1 : onInit" ),
						new AddChild( prog.container, b1 )
					);
				},
				onGoto: function():void {
					this.addCommand(
						new Trace( "scene1 : onGoto" ),
						new RemoveChild( prog.container, b1 )
					);
				},
				onUnload: function():void {
					this.addCommand(
						new Trace( "scene1 : onUnload" )
					);
				}
			} ) );

			prog.root.addScene( new SceneObject( "scene2", {
				onLoad: function():void {
					this.addCommand(
						new Trace( "scene2 : onLoad" )
					);
				},
				onInit: function():void {
					this.addCommand(
						new Trace( "scene2 : onInit" ),
						new AddChild( prog.container, b2 )
					);
				},
				onGoto: function():void {
					this.addCommand(
						new Trace( "scene2 : onGoto" ),
						new RemoveChild( prog.container, b2 )
					);
				},
				onUnload: function():void {
					this.addCommand(
						new Trace( "scene2 : onUnload" )
					);
				}
			} ) );

			prog.goto( new SceneId( "/index/scene1" ) );
		}
	}
}

まず /index/scene1 に行くと赤いボタンが配置され、クリックすると /index/scene2 に飛び青いボタンが表示され、そのボタンをクリックすると設定されていない /index/scene3 に遷移するよう要求しエラーを発生させます。

出力結果

onProcessStart :null
onProcessScene :load
onProcessEvent :load
onProcessEvent :descend
onProcessScene :load
onProcessEvent :load
scene1 : onLoad
onProcessEvent :init
scene1 : onInit
onProcessComplete :init
------
onProcessStart :init
onProcessEvent :goto
scene1 : onGoto
onProcessEvent :unload
scene1 : onUnload
onProcessScene :load
onProcessEvent :load
scene2 : onLoad
onProcessEvent :init
scene2 : onInit
onProcessComplete :init
------
onProcessStart :init
onProcessEvent :goto
scene2 : onGoto
onProcessEvent :unload
scene2 : onUnload
[ERROR] 移動先のシーンが存在しません, 目的地 = /index/scene3
onProcessError :load

scene2 の onInit イベント内で中断実行を行う処理に変更してみる。

onInit: function():void {
	this.addCommand(
		new Trace( "scene2 : onInit" ),
		function():void { this.interrupt(); },
		new Trace( "中断実行後" )
	);
}<

出力結果

onProcessStart :null
onProcessScene :load
onProcessEvent :load
onProcessEvent :descend
onProcessScene :load
onProcessEvent :load
scene1 : onLoad
onProcessEvent :init
scene1 : onInit
onProcessComplete :init
------
onProcessStart :init
onProcessEvent :goto
scene1 : onGoto
onProcessEvent :unload
scene1 : onUnload
onProcessScene :load
onProcessEvent :load
scene2 : onLoad
onProcessEvent :init
scene2 : onInit
中断実行後
onProcessInterrupt :init
------

interrupt メソッドに引数 true を渡して、強制中断実行に変更するとそのあとの処理は実行されず終了する。

function():void { this.interrupt( true ); }
  • onProcessStart で始まり正常終了した場合は onProcessComplete で終わる
  • onProcessEvent と SceneObject イベントは対で実行され、onProcessEvent が常に先に実行される
  • onProcessScene イベントはシーンに入る直前に実行される
  • 階層化されていれば通過シーン到達直前もすべて onProcessScene は実行される

Comments:0

Comment Form
Remember personal info

Trackbacks:0

Trackback URL for this entry
http://blog.cuegraphix.com/wp-trackback.php?p=41
Listed below are links to weblogs that reference
ProcessEvent イベントフローについて(2) from blog.cuegraphix.com

Home > ActionScript | Progression > ProcessEvent イベントフローについて(2)

Search
Feeds
Meta

Return to page top