Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Loader_fla
- {
- import flash.display.MovieClip;
- import flash.net.URLLoader;
- import flash.events.Event;
- import flash.net.URLVariables;
- import flash.system.ApplicationDomain;
- import flash.display.Loader;
- import flash.events.IOErrorEvent;
- import flash.net.URLRequest;
- import flash.system.LoaderContext;
- import flash.events.ProgressEvent;
- import flash.system.Security;
- public dynamic class MainTimeline extends MovieClip
- {
- public var mcLoading:MovieClip;
- public var sFile;
- public var sTitle;
- public var sBG:String;
- public var sURL:String;
- public var versionURL:String;
- public var loader:URLLoader;
- public var loaderVars;
- public var titleDomain:ApplicationDomain;
- public function MainTimeline()
- {
- super();
- addFrameScript(0,this.frame1);
- }
- public function onDataComplete(evt:Event) : void
- {
- trace("onDataComplete:" + evt.target.data);
- var vars:URLVariables = new URLVariables(evt.target.data);
- if(vars.status == "success")
- {
- this.sFile = vars.sFile;
- this.sTitle = vars.sTitle;
- this.sBG = vars.sBG;
- this.loaderVars = vars;
- this.loadTitle();
- this.loadGame();
- }
- else
- {
- trace(vars.strReason);
- }
- }
- public function loadTitle() : void
- {
- var loader:Loader = new Loader();
- loader.contentLoaderInfo.addEventListener(Event.COMPLETE,this.onTitleComplete);
- loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,this.onError);
- loader.load(new URLRequest(this.sURL + "gamefiles/title/" + this.sBG),new LoaderContext(false,this.titleDomain));
- }
- public function onTitleComplete(e:Event) : void
- {
- trace("Title Loaded");
- }
- public function loadGame() : void
- {
- var loader:Loader = new Loader();
- loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,this.onProgress);
- loader.contentLoaderInfo.addEventListener(Event.COMPLETE,this.onComplete);
- loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,this.onError);
- loader.load(new URLRequest(this.sURL + "gamefiles/" + this.sFile));
- this.mcLoading.strLoad.text = "Loading 0%";
- }
- public function onProgress(evt:ProgressEvent) : void
- {
- var percent:int = evt.currentTarget.bytesLoaded / evt.currentTarget.bytesTotal * 100;
- this.mcLoading.strLoad.text = "Loading " + percent + "%";
- }
- public function onComplete(e:Event) : void
- {
- var v:* = undefined;
- var stg:* = stage;
- stg.removeChildAt(0);
- var game:* = stg.addChild(MovieClip(Loader(e.target.loader).content));
- for(v in root.loaderInfo.parameters)
- {
- trace(v + ": " + root.loaderInfo.parameters[v]);
- game.params[v] = root.loaderInfo.parameters[v];
- }
- game.params.sURL = this.sURL;
- game.params.sTitle = this.sTitle;
- game.params.vars = this.loaderVars;
- game.titleDomain = this.titleDomain;
- }
- public function onError(e:IOErrorEvent) : void
- {
- trace("Preloader IOError: " + e);
- }
- function frame1() : *
- {
- Security.allowDomain("*");
- this.sURL = this.loaderInfo.url.substring(0,this.loaderInfo.url.lastIndexOf("gamefiles/"));
- trace("sURL: " + this.sURL);
- this.versionURL = "gameversion.asp";
- if(this.sURL.indexOf("cdn.aqworlds.com") >= 0 || this.sURL.indexOf("aqworldscdn.aq.com") >= 0)
- {
- this.versionURL = "http://game.aqworlds.com/game/" + this.versionURL;
- }
- else
- {
- this.versionURL = this.sURL + this.versionURL;
- }
- trace("versionURL: " + this.versionURL);
- this.loader = new URLLoader();
- this.loader.addEventListener(Event.COMPLETE,this.onDataComplete);
- this.loader.load(new URLRequest(this.versionURL));
- this.titleDomain = new ApplicationDomain();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement