ProgressionでSWFProfilerを使う方法

Progressionで右クリックに別のcontextMenuを割り当てようとしてもうまくいきません。
最近よく使うSWFProfilerも同様に使えないので、解決方法を考えてみました。

1.Indexに直接Spriteを置いて、それをSWFProfilerの初期化で渡してしまう方法

var sp:Sprite = new Sprite();
sp.graphics.beginFill(0xFF0000);
sp.graphics.drawRect(0, 0, 100, 100);
stage.addChild(sp);
SWFProfiler.init(stage, sp);

 

2.外部swfを読み込む方法

SWFProfilerを埋め込んだswfを作成し、それを読み込むことで そのエリアでの右クリックはProgressionの影響を受けずSWFProfilerを使うことができます。
画面下部に3px分、透明のSpriteを設置して画面のリサイズにも対応させておきます。

package {
	import flash.display.*
	import flash.events.*
	import com.flashdynamix.utils.SWFProfiler
	public class Profiler extends Sprite {
		public function Profiler() {
			if ( stage) addStage();
			else addEventListener(Event.ADDED_TO_STAGE , addStage);
		}
 
		public function addStage(e = null) {
			stage.scaleMode = StageScaleMode.NO_SCALE
			stage.align = StageAlign.TOP_LEFT
			stage.addEventListener(Event.RESIZE, resize);
			removeEventListener(Event.ADDED_TO_STAGE , addStage);
			SWFProfiler.init(stage, this);
			graphics.beginFill(0xFF0000,0);
			graphics.drawRect(0, -3, stage.stageWidth, 3);
			resize();
		}
 
		private function resize(e:Event=null):void {
			width = stage.stageWidth;
			y = stage.stageHeight;
		}
	}
}

こんな感じでSWFProfilerをインクルードしたswfを作ればよいでしょう。
そして、それをIndexのほうで以下の様に読み込みます。

loader = new Loader()
loader.contentLoaderInfo.addEventListener(Event.COMPLETE , setProfiler);
loader.load(new URLRequest("profiler.swf"));
 
public function setProfiler(e=null):void{
	stage.addChild(loader)
}

これで書き出したprofiler.swfを読み込んでSWFProfilerが使えるようになりました。
もしSWFProfilerを突っ込んだままサーバにあげてしまっても
profiler.swfを削除してしまえばSWFProfilerを使われずに済むということでしょうか・・・

 

下部3px対応の書き出し済みのprofiler.swfを置いておきます。
[ DOWNLOAD ]

Filed under AS3, Progression · Tagged with ,

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

You must be logged in to post a comment.