それはノーだときには、イベントリスナーを削除する必要がありますメモリリークの危険があります。無名関数はこれを困難にする可能性がありますが、あなたはarguments.calleeでそれを行うことができます。
bar.addEventListener(Event.ENTER_FRAME, function(e:Event) {
var b:MovieClip = MovieClip(e.currentTarget);
if(b.currentFrame == mp.getPopularity()){
b.stop();
b.removeEventListener(e.type, arguments.callee);
// ^^ this may work to remove your anonymous listener.
}
});
これについては別の方法があります。 mp.getPopularity()は頻繁に変更されますか? barがplay()の後に変更されない場合は、addFrameScriptを使用できます。 addFrameScriptは0でインデックス付けされているので、フレーム1にスクリプトを追加すると、0を渡す必要があることを忘れないでください。mp.getPopularity()でアクションが発生する場合は、mp.getPopularity()を渡す必要があります。 - 1.
var framescript:Function = function():void{
bar.stop();
bar.addFrameScript(bar.currentFrame-1, null);
// ^^ nulling the framescript after
// ^^ it is no longer needed.
}
bar.stop(); // Generally a good idea to call stop before calling addFrameScript
bar.addFrameScript(mp.getPopularity() - 1, framescript);
bar.gotoAndPlay(1); // or wherever it needs to start from.
これは、より正確なソリューションですが、別のmp.getPopularityして後に、この同じバーインスタンスを使用する予定の場合は、設定が完了した後、あなたのframescriptをクリーンアップするために覚えておく必要があります()値です。
あなたはおそらく 'addFrameScript()'を試すことができます - 文書化されていませんが、動作するかもしれません:http://www.kirupa.com/forum/showthread.php?223798-ActionScript-3-Tip-of-the-Day/page22&p = 2098268#post2098268 – divillysausages