I’m building a website to host educational-based flash games for children. Due to the fact that the swfs are +2mb, I decided to write a loader swf to display a downloaded percentage so my users are not staring at a white screen while the actual game is downloading. The loader calls and loads the game correctly when I run it from Flashdevelop on my pc, but not from the site itself. It will fully download the game, but never display it. Here’s the link to my on site loader: http://www.roomrecess.com/loaders/Loader.swf
And here’s my script for the loader itself (Loader.swf):
package
{
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.ProgressEvent;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.system.Security;
import flash.system.SecurityDomain;
public class Main extends Sprite
{
[Embed(source = "../lib/title.png")]
public var sharkTitle:Class;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
Security.allowDomain("*");
Security.allowInsecureDomain("*");
var sharkTitle:Bitmap = new sharkTitle();
sharkTitle.x = 250;
sharkTitle.y = 70;
sharkTitle.height = 150;
sharkTitle.width = 310;
var format:TextFormat = new TextFormat();
format.size = 50;
var percTxt:TextField = new TextField();
percTxt.width = 500;
percTxt.text = " ";
percTxt.setTextFormat(format);
percTxt.x = 300;
percTxt.y = 250;
addChild(sharkTitle);
addChild(percTxt);
function startLoad():void
{
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest("http://www.roomrecess.com/games/WordShark.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
}
function onCompleteHandler(loadEvent:Event):void
{
addChild(loadEvent.currentTarget.content);
}
function onProgressHandler(mProgress:ProgressEvent):void
{
var percent:Number = mProgress.bytesLoaded / mProgress.bytesTotal;
percent = percent * 100;
Math.ceil(percent);
format.size = 50;
percTxt.setTextFormat(format);
percTxt.text = String(Math.ceil(percent)) + "% loaded";
percTxt.setTextFormat(format);
if (percent > 99) { percTxt.visible = false;}
}
startLoad();
}
}
}
Thanks you.