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

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

Sceneでのイベントフローはいろんな方が書いておられるので非常に勉強になりますが、ProcessEventについてはあまり見つけられなかったので、試してみました。

Progressionインスタンスのイベントハンドラメソッドには

  • onProcessStart
  • onProcessScene
  • onProcessComplete
  • onProcessEvent
  • onProcessError
  • onProcessInterrupt

が用意されています。
これがSceneObjectのonLoadやonInitからみてどんなタイミングで実行されるのかテストするために、次のようなIndexクラスを作成します。

package
{
	import jp.progression.casts.CastDocument;
	import jp.progression.commands.Goto;
	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 ); }
			prog.onProcessEvent     = function() { trace( "onProcessEvent :" + prog.eventType ); }
			prog.onProcessError     = function() { trace( "onProcessError :" + prog.eventType ); }
			prog.onProcessInterrupt = function() { trace( "onProcessInterrupt :" + prog.eventType ); }
			
			prog.root.addScene( new SceneObject( "scene1", {
				onLoad: function():void {
					this.addCommand(
						new Trace( "scene1 : onLoad" )
					);
				},
				onInit: function():void {
					this.addCommand(
						new Trace( "scene1 : onInit" ),
						// scene2へ移動
						new Goto( new SceneId( "/index/scene2" ) )
					);
				},
				onGoto: function():void {
					this.addCommand(
						new Trace( "scene1 : onGoto" )
					);
				},
				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 Goto( new SceneId( "/index/scene3" ) )
					);
				},
				onGoto: function():void {
					this.addCommand(
						new Trace( "scene2 : onGoto" )
					);
				},
				onUnload: function():void {
					this.addCommand(
						new Trace( "scene2 : onUnload" )
					);
				}
			} ) );
			
			prog.goto( new SceneId( "/index/scene1" ) );
		}
	}
}

出力結果

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

想像通りですが、SceneEvent が発生した際には onProcessEvent が実行されてから、シーンの各イベントハンドラが実行されるようです。
ただこの検証だとscene1に到達した瞬間のコマンドリスト内で強制的にscene2へGoToで飛ばしているので、中断実行であるonProcessInterrupt が入ると思っていたんですが、scene1 : onInitの次は onProcessStart :init が実行されてますね。
多分最後に2つ出力されているonProcessInterrupt のどちらかがこれに相当するのでしょうか?

scene1 の onGoto 内に new Wait( 1000 ) のようにWaitコマンドを挟むと、onProcessInterrupt がその時点で出力されます。もしかすると中断実行も非同期処理になっているのかな?

ない頭でGotoコマンドやSceneManagerを模索してみましたが、Gotoの場合実行中であれば中断実行してそのイベントを受け取りgoto処理を行うので、中断実行処理は確実に終了しており、addEventListenerの優先度の問題でした。
しかしこんな無茶な使い方をしても問題なく処理が終了するCommandクラスはすばらしい。
僕だったらゴミが残りまくりになっちゃうんだろうなぁ・・・

Comments:1

Lewis Cowles 10-04-13 (火) 2:04

Hi, thanks for your fav at WonderFL, nice loader, happy coding, possibly check out my blog for freebies

Comment Form
Remember personal info

Trackbacks:0

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

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

Search
Feeds
Meta

Return to page top