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();
}- /**
- * 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();
- }
一応ソース置いとく。
SWFProfiler.as.zip
About this entry
You’re currently reading “ProgressionでSWFProfilerを使う,” an entry on jp.ferv.blog
- Published:
- Thu, Jun 25th, 2009 at 4:54 PM
- Author:
- dsk
- Category:
- Web
- Tags:
- ActionScript 3.0, Progression, SWFProfiler
No comments
Jump to comment form | comments rss | trackback uri