Advertisement
Guest User

AQWorlds Loader Code (w/ Loading Bar)

a guest
Dec 20th, 2014
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. import flash.events.Event;
  2.  
  3. //Comments by Oliboli8769
  4. //CHANGES FOR THE LOADING BAR ARE IN CAPS
  5.  
  6. Security.allowDomain("*");
  7. //URLs as Strings used for easiness
  8. var sURL1 = "http://aqworldscdn.aq.com/game/";
  9. var sURL2 = "http://cdn.aqworlds.com/game/";
  10. var sFile; //used to store game version string
  11. var versionLoader:URLLoader;
  12. var Game:Object;
  13. var swfContext:LoaderContext;
  14. var swfLoader:Loader;
  15. var swfRequest:URLRequest;
  16.  
  17. GetVersion(); //starts game load
  18.  
  19. function GetVersion()
  20. {
  21. //checks for most recent game version from ASP file
  22. versionLoader = new URLLoader();
  23. versionLoader.addEventListener(Event.COMPLETE, onVersionComplete); //adds event listener for when the ASP is loaded
  24. versionLoader.load(new URLRequest(sURL1 + "gameversion.asp")); //same as http://aqworldscdn.aq.com/game/gameversion.asp
  25. }
  26. function onVersionComplete(param1:Event)
  27. {
  28. //ASP file has now been fully loaded
  29. var vars:URLVariables;
  30. vars = new URLVariables(param1.target.data); //reads variables held on loaded ASP
  31. if (vars.status == "success") //checks the 'status' var on ASP
  32. {
  33. //after confirmation
  34. sFile = vars.sFile; //reads game version linkage and saves as the variable sFile
  35. LoadGame(); //now the version is found, we can load the game
  36. }
  37. }
  38. function LoadGame()
  39. {
  40. swfContext = new LoaderContext(false,ApplicationDomain.currentDomain,null);
  41. swfLoader = new Loader();
  42. swfRequest = new URLRequest(sURL2 + "gamefiles/" + sFile); //using sFile from before as updated game linkage
  43. swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onGameComplete); //adds event listener for the game load
  44. swfLoader.contentLoaderInfo.addEventListener(flash.events.ProgressEvent.PROGRESS, onGameProgress); //adds event listener for how much the game has loaded
  45. swfLoader.load(swfRequest, swfContext);
  46. stage.quality = StageQuality.LOW; //sets stage quality to low, possibly reducing lag (optional)
  47. }
  48. function onGameComplete(loadEvent:Event)
  49. {
  50. stage.addChildAt(loadEvent.currentTarget.content, 0); //adds the loaded game content to the stage
  51. loadEvent.currentTarget.content.y = 0.0;
  52. loadEvent.currentTarget.content.x = 0.0;
  53. Game = Object(loadEvent.currentTarget.content); //stores loaded content onto the Object Game
  54. Game.params.sURL2 = sURL2;
  55. //WHEN THE LOAD IS COMPLETE, HIDE THE LOADING BAR
  56. loadingBar.visible = false;
  57. }
  58. function onGameProgress(arg1:flash.events.ProgressEvent):void
  59. {
  60. //this can be used for progress bars/loaders before trainers
  61. //CHANGES THE X SCALE OF THE LOADING BAR BY
  62. var percentage:*=arg1.bytesLoaded / arg1.bytesTotal;
  63. trace(loc1 * 100); //traces how much the game has loaded as a percentage
  64. loadingBar.scaleX = percentage; //WHERE THE SCALE CHANGE TAKES PLACE
  65. return;
  66. }
  67. stop();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement