당신은 이벤트 리스너를 제거해야 청취 기능으로
function playUntil(target:MovieClip, frame:int):void
{
target.stopFrame = frame; // Works because MovieClip is dynamic.
target.addEventListener(Event.ENTER_FRAME, _checkFrame);
}
더 오래 필요합니다. 그렇지 않으면 메모리 누수의 위험이 있습니다. 무명 함수는 이것을 어렵게 만들 수 있지만 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 나중에이 같은 막대 인스턴스를 사용하려는 경우 당신이 당신의 프레임 스크립트를 정리하는 것을 기억해야합니까() 값.
아마도'addFrameScript()'를 시도해 볼 수 있습니다 - 문서화되어 있지 않지만 작동 할 수 있습니다 : http://www.kirupa.com/forum/showthread.php?223798-ActionScript-3-Tip-of-the-Day/page22 & p = 2098268 # post2098268 – divillysausages