Advertisement
Guest User

Loader

a guest
Apr 28th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Security.allowDomain("*");
  2. //imports
  3. import flash.net.URLRequest;
  4. import flash.display.Loader;
  5. import flash.events.Event;
  6. import flash.events.ProgressEvent;
  7. import flash.system.LoaderContext;
  8. import flash.external.ExternalInterface;
  9. //variable declarations
  10. var sURL = "http://cdn.aqworlds.com/game/";
  11. var sFile;
  12.  
  13. var versionLoader:URLLoader;
  14.  
  15. var game:Object;
  16. var swfContext:LoaderContext;
  17. var swfLoader:Loader;
  18. var swfRequest:URLRequest;
  19. var percent:Number;
  20.  
  21. //function declarations
  22. function LoadGame()
  23. {
  24.     swfContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
  25.     swfLoader = new Loader();
  26.     swfRequest = new URLRequest(sURL + "gamefiles/" + sFile);
  27.    
  28.     swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onGameComplete);
  29.     swfLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onGameProgress);
  30.     swfLoader.load(swfRequest, swfContext);
  31.     stage.quality = StageQuality.LOW;
  32.    
  33.     percent = 0;
  34. }
  35.  
  36. function onGameComplete(loadEvent:Event)
  37. {
  38.     stage.addChildAt(loadEvent.currentTarget.content, 0);
  39.     loadEvent.currentTarget.content.y = 0.0;
  40.     loadEvent.currentTarget.content.x = 0.0;
  41.     game = Object(loadEvent.currentTarget.content);
  42.     game.params.sURL = sURL;
  43.     this.gotoAndStop(2);
  44. }
  45.  
  46. function onGameProgress(swfProgress:ProgressEvent)
  47. {
  48.     percent = Math.round((swfProgress.bytesLoaded/swfProgress.bytesTotal) * 100);
  49.     LoadingBar.width = percent*2
  50.     LoadingText.text = "Loading Game " + percent + "%";
  51.     this.refresh;
  52. }
  53.  
  54. function GetVersion()
  55. {
  56.      versionLoader = new URLLoader();
  57.      versionLoader.addEventListener(Event.COMPLETE, onVersionComplete);
  58.      versionLoader.load(new URLRequest(sURL + "getversion.asp"));
  59. }
  60.  
  61. function onVersionComplete(param1:Event)
  62. {
  63.     var vars:URLVariables;
  64.     vars = new URLVariables(param1.target.data);
  65.     if (vars.status == "success")
  66.     {
  67.         sFile = vars.sFile;
  68.         LoadGame();
  69.     }
  70.     else
  71.     {
  72.         this.gotoAndStop(1);
  73.     }
  74. }
  75.  
  76. //Start doing stuff
  77. GetVersion();
  78.  
  79. stop();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement