Created
July 13, 2010 16:57
-
-
Save Stray/474159 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
import flash.display.MovieClip; | |
public class FrameScriptManager extends Object | |
{ | |
private var _targetMC:MovieClip; | |
private var _frameNumbersToFunctionsArray:Array; | |
public function FrameScriptManager(targetMC:MovieClip) | |
{ | |
_targetMC = targetMC; | |
_frameNumbersToFunctionsArray = new Array(); | |
super(); | |
} | |
public function addFrameScriptAtFrame(frameNumber:int, newFrameActions:Function):void | |
{ | |
var existingFrameActions:Function = getExistingActionsForFrame(frameNumber); | |
var totalFrameActions:Function = function():void | |
{ | |
existingFrameActions(); | |
newFrameActions(); | |
} | |
_targetMC.addFrameScript(frameNumber-1, totalFrameActions); | |
_frameNumbersToFunctionsArray[frameNumber] = totalFrameActions; | |
} | |
public function getFrameScriptAtFrame(frameNumber:int):Function | |
{ | |
return getExistingActionsForFrame(frameNumber); | |
} | |
private function getExistingActionsForFrame(frameNumber:int):Function | |
{ | |
if(_frameNumbersToFunctionsArray[frameNumber] != null) | |
{ | |
return _frameNumbersToFunctionsArray[frameNumber]; | |
} | |
return grabFrameCode(frameNumber); | |
} | |
private function grabFrameCode(frameNumber:int):Function | |
{ | |
var timelineFunction:Function = _targetMC['getFrameScriptAt'](frameNumber); | |
if((timelineFunction != null) && (timelineFunction is Function)) | |
{ | |
return timelineFunction; | |
} | |
var emptyFunction:Function = function():void {}; | |
return emptyFunction; | |
} | |
} | |
} | |
// your mc needs to implement this interface, even though it is used dynamically in the actual FrameScriptManager itself (due to ApplicationDomain issues on loaded swfs) | |
package | |
{ | |
public interface IInjectableTimeline | |
{ | |
function getFrameScriptAt(frameNumber:int):Function; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment