I can’t get the preloader to show when loading these external swfs. The functionality works but I need to show the preloader. When I test it the first movie will show the preloader. Does anything in my code keep the preloader from showing?
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*.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);
trace( "loader.load" );
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;
}
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
{
//trace( "completed + " + prevSection );
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{
//trace( "outroFinished " );
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 );
}
private function stopAll():void
{
for(var i:int=0;i < section_buttons_array.length;i++)
{
section_buttons_array*.stop();
sections_array*.stop();
}
}
private function addMenuEvents():void
{
for(var i:int=0;i < section_buttons_array.length;i++)
{
section_buttons_array*.mouseChildren=false;
section_buttons_array*.buttonMode=true;
section_buttons_array*.id=i;
section_buttons_array*.isPressed=false;
section_buttons_array*.addEventListener(MouseEvent.MOUSE_OVER,setOver);
section_buttons_array*.addEventListener(MouseEvent.MOUSE_OUT,setOut);
section_buttons_array*.addEventListener(MouseEvent.MOUSE_DOWN,setDown);
section_buttons_array*.addEventListener(MouseEvent.MOUSE_UP,setUp);
}
}
private function setOver(evt:MouseEvent):void
{
if(evt.target.isPressed==false)
evt.target.gotoAndStop(2);
}
private function setOut(evt:MouseEvent):void
{
if(evt.target.isPressed==false)
evt.target.gotoAndStop(1);
}
private function setDown(evt:MouseEvent):void
{
nextSection=evt.target.id;
checkState(evt.target.id);
evt.target.gotoAndStop(3);
loadSection( evt );
}
private function setUp(evt:MouseEvent):void
{
if(evt.target.isPressed==false)
evt.target.gotoAndStop(1);
}
private function checkState(n:int):void
{
for(var i:int=0;i < section_buttons_array.length;i++)
{
if(i==n)
section_buttons_array*.isPressed=true;
else
{
section_buttons_array*.isPressed=false;
section_buttons_array*.gotoAndStop(1);
}
}
}
}
}