ProgressionでSWFProfilerを使う

Progressionを使いつつSWFProfilerを使いたいんだけど、Progressionが作ってるコンテキストメニューもそのまま使いたい。
SWFProfilerは、initの第一引数で渡すInteractiveObjectのコンテキストメニューにアイテムを追加(実際には上書き)するんだけど、ついでに任意のContextMenuの参照を渡してそこにもアイテムを追加するようにすればいいかと。

Progressionが作ってくれるIndex.asのコンストラクタで、SWFProfiler.init(this, false, Progression.uiContextMenu);したサンプル。(第二引数についてはSWFProfilerをデフォルトで表示するを参照)
progression_swfprofiler.swf
Progression 3.1 - API ReferenceによるとProgression.uiContextMenuで取得できるコンテキストメニューは「背景に関連付けられている CastObjectContextMenu インスタンス」てことなんで、背景のところでしか"Show Profiler"出せないけどとりあえずいっか。ちなみに、ShowProfilerする用のインスタンス一個作ってもいいかもって人にはProgression SWF Profiler デバック やってみたっていう方法もあるみたい。

  • ActionScript
  • SWFProfiler.as
  • Source
/**
 * Initiates the SWFProfiler to the ContextMenu of the reference passed.
 */
public static function init(context : InteractiveObject, showProfiler:Boolean = false, ...contextMenus) : void {
	if(inited) return;

	inited = true;
	stage = context.stage;

	content = new ProfilerContent();
	frame = new Sprite();

	minFps = Number.MAX_VALUE;
	maxFps = Number.MIN_VALUE;
	minMem = Number.MAX_VALUE;
	maxMem = Number.MIN_VALUE;

	ci = new ContextMenuItem("Show Profiler", true);
	addEvent(ci, ContextMenuEvent.MENU_ITEM_SELECT, onSelect);
	var cm : ContextMenu = new ContextMenu();
	cm.hideBuiltInItems();
	cm.customItems.push(ci);
	context.contextMenu = cm;

	var contextMenu:*;
	for each (contextMenu in contextMenus) contextMenu.customItems.push(ci);

	start();

	if (showProfiler) show();
}
  1. /**
  2.  * Initiates the SWFProfiler to the ContextMenu of the reference passed.
  3.  */
  4. public static function init(context : InteractiveObject, showProfiler:Boolean = false, ...contextMenus) : void {
  5.     if(inited) return;
  6.  
  7.     inited = true;
  8.     stage = context.stage;
  9.  
  10.     content = new ProfilerContent();
  11.     frame = new Sprite();
  12.  
  13.     minFps = Number.MAX_VALUE;
  14.     maxFps = Number.MIN_VALUE;
  15.     minMem = Number.MAX_VALUE;
  16.     maxMem = Number.MIN_VALUE;
  17.  
  18.     ci = new ContextMenuItem("Show Profiler", true);
  19.     addEvent(ci, ContextMenuEvent.MENU_ITEM_SELECT, onSelect);
  20.     var cm : ContextMenu = new ContextMenu();
  21.     cm.hideBuiltInItems();
  22.     cm.customItems.push(ci);
  23.     context.contextMenu = cm;
  24.  
  25.     var contextMenu:*;
  26.     for each (contextMenu in contextMenus) contextMenu.customItems.push(ci);
  27.  
  28.     start();
  29.  
  30.     if (showProfiler) show();
  31. }

一応ソース置いとく。
SWFProfiler.as.zip


About this entry