Hi,
I'm trying to set up a preloader to show the load progress of the main swf, which has all of it's assets embedded. I found the factory class method as described on bit-101, but no load progress ever seems to show. The swf loads fine, but the bytesLoaded is always equal to bytesTotal and therefore the preloader is never called.
This is the factory class I'm using
package src
{
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.events.Event;
import flash.utils.getDefinitionByName;
/**
* ...
* @author DefaultUser (Tools -> Custom Arguments...)
*/
public class Factory extends MovieClip
{
private var preloader:Preloader;
public function Factory()
{
stop();
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
addEventListener(Event.ENTER_FRAME, enterFrame);
}
public function enterFrame(e:Event):void
{
trace(root.loaderInfo.bytesLoaded, root.loaderInfo.bytesTotal);
if (framesLoaded == totalFrames) {
removeEventListener(Event.ENTER_FRAME, enterFrame);
nextFrame();
init();
}
else {
var percent:Number = root.loaderInfo.bytesLoaded / root.loaderInfo.bytesTotal;
trace(percent);
}
}
private function init():void
{
var mainClass:Class = Class(getDefinitionByName("Main"));
if (mainClass) {
var mainApp:Object = new mainClass();
addChild(mainApp as DisplayObject);
mainApp.init();
}
}
}
}
The trace called on the enterFrame event shows that bytesLoaded and bytesTotal are equal.
And this is the Main class called when the swf loads.
package
{
import flash.display.Sprite;
[Frame(factoryClass="src.Factory")]
public class Main extends Sprite
{
[Embed(source="images/FinalImg01.jpg")]
private var Image1:Class;
[Embed(source="images/FinalImg02.jpg")]
private var Image2:Class;
[Embed(source="images/FinalImg03.jpg")]
private var Image3:Class;
public function init():void
{
trace("loaded");
}
}
}
This correctly calls the Factory class first, and then instansiates Main and calls init(). But as I mentioned above the preloading is never shown as it seems to be loading everything straight away.
Is this a problem with the way I'm embedding the images or because I'm testing locally?
Anybody else come across these issues?
Thanks Rich