Reseting Loaded swfs
I used a custom base to load in a run all swfs. A semi-intelligent brain behind ever flash project. One piece that's always been overly complicate was "starting over". When a dead-end interaction gets to the end and the user wants to start again. Prior I was literally writing custom resets for all states / storage vars... horribly over complicated.
This code removes the swfs. "Clones" them and then re-adds them so I can run my standar initialization.
In my load class:
public function hardReset(comp:Function):void
{
_loadComplete = comp;
_loc.removeChild(_swfLoader);
cloneLoader(_swfLoader);
}
private function cloneLoader(source:SafeLoader):void
{
_swfLoader = new SafeLoader();
_swfLoader.loadBytes(source.contentLoaderInfo.bytes);
_swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCloneComplete);
}
private function onCloneComplete(e:Event):void
{
_loc.addChild(_swfLoader);
_loadComplete(e, _filename);
}
// used by ControllerSWF to restack the order when a hard reset is complete
public function moveTop():void
{
new MoveTop(_swfLoader, _loc);
}
In my swf controller:
public function hardReset():void
{
_baseRef._chalk.traceOut("ControllerSWf => hardReset");
_resetCount = 0;
var i:Number;
for( i=0; i < _swfLoaders.length; i++)
{
_swfLoaders[i].hardReset(hardResetComplete);
}
}
private function hardResetComplete(e:Event, f:String):void
{
_baseRef._chalk.traceOut("Hard Reset - Load SWF: " + f, "end");
var currentIndex:Number = _swfLabels.indexOf(f);
_swfs[currentIndex] = e.target.content;
TweenMax.to(_swfs[currentIndex].contentHolder, 0, {autoAlpha:0});
_swfs[currentIndex].setup(_baseRef);
_resetCount++;
if(_resetCount == _swfLoaders.length)
{
// restacks the proper order
var i:Number;
for( i=0; i < _swfs.length; i++)
{
_swfLoaders[i].moveTop();
}
// start setup as if it's the first run
initialSetup();
}
}












