Create a gist now

Instantly share code, notes, and snippets.

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