-
help with loading order
I have a main swf that I load external swfs onto the stage. I am trying to fix the loading order. Currently when a button is pressed, the swf is preloaded, the current swf is on the stage with the preloader showing, then the preloader disappears and the swf plays the outro transition.
I can't figure how to change the order so that currently loaded swf is removed from the stage, show the preloader and then show the new swf.
Code:
package
{
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.MouseEvent;
import flash.events.*;
import flash.display.DisplayObject;
import SWFManager;
public class V2 extends MovieClip
{
private var sections_array:Array;
private var section_buttons_array:Array;
private var loader:Loader;
private var sectionHolder : MovieClip;
private var swf:String;
private var nextSection:int;
private var id:int=0;
private var homeLoc = "./swfs/home.swf";
private var currentSection:MovieClip;
private var playingOutro:Boolean = false;
private var nextSectionIsLoaded:Boolean = false;
private var lastSectionIsOver:Boolean = false;
private var currSection : Number;
private var prevSection : Number = -1;
public function V2()
{
init();
}
private function init():void
{
stop();
stage.frameRate=31;
preloader_mc.visible=false;
preloader_mc.fill_mc.width=0;
sectionHolder = new MovieClip();
sectionHolder.x = 37;
sectionHolder.y = 42;
addChild( sectionHolder );
sections_array = new Array('./swfs/section1.swf',
'./swfs/section2.swf',
'./swfs/section3.swf',
'./swfs/section4.swf',
'./swfs/section5.swf');
section_buttons_array = new Array(btn1,btn2,btn3,btn4,btn5);
addMenuListener();
addMenuEvents();
addEventListener( "removeMe" , outroFinished );
loader = new Loader();
loadSection( null );
}
private function addMenuListener():void
{
for(var i:int=0;i < section_buttons_array.length ;i++){
section_buttons_array[i].id=i;
}
}
private function loadSection( evt: Event ):void
{
if( evt == null ) {
swf="./swfs/home.swf"
currSection = 0;
} else {
prevSection = currSection;
currSection = evt.target.id;
swf=sections_array[currSection];
currSection ++;
};
var request:URLRequest=new URLRequest(swf);
initListeners(loader.contentLoaderInfo);
loader.load(request);
}
private function initListeners(dispatcher:IEventDispatcher):void
{
dispatcher.addEventListener(Event.OPEN,start);
dispatcher.addEventListener(ProgressEvent.PROGRESS,atLoading);
dispatcher.addEventListener(Event.COMPLETE,completed);
}
private function removeListeners(dispatcher:IEventDispatcher):void
{
dispatcher.removeEventListener(Event.OPEN,start);
dispatcher.removeEventListener(ProgressEvent.PROGRESS,atLoading);
dispatcher.removeEventListener(Event.COMPLETE,completed);
}
private function start(event:Event):void
{
preloader_mc.visible=true;
addChild(preloader_mc);
}
private function atLoading(event:ProgressEvent):void
{
var n:uint=(event.bytesLoaded/event.bytesTotal)*100;
preloader_mc.fill_mc.width=n;
}
private function completed(event:Event):void
{
if( prevSection != -1 ) {
var targ : Object = SWFManager.SWFArray[ prevSection ];
targ.gotoAndPlay( "out" );
preloader_mc.visible=false;
} else {
sectionHolder.addChild(loader.content);
};
}
private function outroFinished(e:Event):void{
var tmpHolder : MovieClip = new MovieClip();
addChild( tmpHolder );
tmpHolder.addChild( loader.content );
sectionHolder.removeChildAt( 0 );
sectionHolder.addChild( tmpHolder );
var loadtarg : Object = SWFManager.SWFArray[ currSection ];
trace( "currSection : " + currSection );
loadtarg.gotoAndPlay( 2 );
}
-
-
If you don't care about the outro, you can removeChild and unload the current swf in loadSection - then add your load progress indicator there as well. Then add the new swf and remove the preloader on the load complete instead of on the old swfs outro.
When you're changing stuff, make sure you clean up the eventHandler for the outro - that could cause some interference.
-
Thanks. Not sure what you mean by "if I don't care about the outro". Yes I still want to show the outro, then show the new swf.
-
Ok picking this back up after a few months. Still need help. I can't figure how to get the order right. I need the loaded movie to play out, then show preloader, then preloader disappear then next loaded SWF play.
-
-
Can anyone help. I have been trying to work this out since last year. Thanks.
-
I can't believe its been 8 months since I last visited this. Still needing help getting this to work. Thanks.