Guest User

Untitled

a guest
May 23rd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. /********************************************
  2. * Preloader
  3. *
  4. * Description: Loads all xml and swfs.
  5. * @author Paul Terhaar
  6. * @since 10-25
  7. * Copyright (C) 2008 Wirestone All Rights Reserved.
  8. *
  9. * -----------------------------------------
  10. * Change Log:
  11. * -----------------------------------------
  12. * date: by: description:
  13. * -- -- --
  14. *
  15. * -----------------------------------------
  16. ********************************************/
  17.  
  18. package {
  19. import flash.display.MovieClip;
  20. import flash.events.Event;
  21. import com.stimuli.loading.BulkLoader;
  22. import com.stimuli.loading.BulkProgressEvent;
  23. import com.hp.kiosk.ProductSorter;
  24.  
  25. public class Preloader extends MovieClip {
  26.  
  27. // _mainMC is what the main swf is loaded into
  28. // typed as "*" because type is not known at compile time
  29. private var _mainMC:*;
  30.  
  31. // BulkLoaders
  32. private var _XMLLoader:BulkLoader;
  33. private var _assetLoader:BulkLoader;
  34.  
  35. // load vars
  36. private var _masterExternalBytesLoaded:Number = 0;
  37. private var _masterExternalBytesTotal:Number = 0;
  38.  
  39. // this is where all xml and product/search arrays are stored
  40. private var _productSorter = new ProductSorter ();
  41.  
  42. /**
  43. * Constructor
  44. */
  45. public function Preloader () {
  46. init ();
  47. }
  48.  
  49. /**
  50. * Create loaders for xml and swfs
  51. */
  52. private function init ():void {
  53. // load the xml
  54. _XMLLoader = new BulkLoader ("XMLLoader");
  55. _XMLLoader.logLevel = BulkLoader.LOG_SILENT;; // LOG_SILENT, LOG_INFO, LOG_VERBOSE - set level to verbose, for debugging only
  56. _XMLLoader.add("assets/xml/printer_search.xml", {id:"printer_search", maxTries:10, priority:20});
  57. _XMLLoader.add("assets/xml/printer_details.xml", {id:"printer_details", maxTries:10, priority:20});
  58. _XMLLoader.add("assets/xml/computer_search.xml", {id:"computer_search", maxTries:10, priority:20});
  59. _XMLLoader.add("assets/xml/computer_details.xml", {id:"computer_details", maxTries:10, priority:20});
  60. _XMLLoader.add("assets/xml/search_options.xml", {id:"search_options", maxTries:10, priority:20});
  61. _XMLLoader.addEventListener(BulkLoader.COMPLETE, XMLLoaded);
  62. _XMLLoader.start ();
  63.  
  64. // creates a BulkLoader instance with a name of "main-site", that can be used to retrieve items without having a reference to this instance
  65. _assetLoader = new BulkLoader("main-site");
  66. _assetLoader.logLevel = BulkLoader.LOG_SILENT; // LOG_SILENT, LOG_INFO, LOG_VERBOSE - set level to verbose, for debugging only
  67. _assetLoader.add("main.swf", { id:"mainMC", maxTries:10 } );
  68. _assetLoader.add("assets/video/TouchSmartII_1055x954.flv", { id:"demoVideo", maxTries:10, pausedAtStart:true } );
  69. _assetLoader.addEventListener(BulkLoader.PROGRESS, onAllItemsProgress);
  70. _assetLoader.addEventListener(BulkLoader.COMPLETE, onAllItemsLoaded);
  71. };
  72.  
  73. /**
  74. * @param event BulkProgressEvent
  75. * When xml is loaded, store xml in _productSorter
  76. * then start the swf loader
  77. */
  78.  
  79. private function XMLLoaded (event:BulkProgressEvent):void {
  80. // set xml document vars on productSorter
  81. _productSorter.printerSearchXML = _XMLLoader.getXML("printer_search");;
  82. _productSorter.printerDetailsXML = _XMLLoader.getXML("printer_details");;
  83. _productSorter.computerSearchXML = _XMLLoader.getXML("computer_search");;
  84. _productSorter.computerDetailsXML = _XMLLoader.getXML("computer_details");;
  85. _productSorter.searchOptionsXML = _XMLLoader.getXML("search_options");;
  86.  
  87. // once the xml is loaded, load the other stuff
  88. _assetLoader.start();
  89. };
  90.  
  91. /**
  92. * @param event BulkProgressEvent
  93. * This evt is a "super" progress event, it has all the information you need to
  94. * display progress by many criterias (bytes, items loaded, weight)
  95. * this function is currently unused.
  96. * if we were displaying a progress bar, this is where the preloader would be updated
  97. */
  98. private function onAllItemsProgress (event:BulkProgressEvent):void {
  99. _masterExternalBytesLoaded = event.bytesLoaded;
  100. _masterExternalBytesTotal = event.bytesTotal;
  101. var loadedWeightPercent = event.weightPercent;
  102.  
  103. if (loadedWeightPercent != 0){
  104. if (loadedWeightPercent >= 1){
  105. // _loaderAnimation.handleComplete ();
  106. } else {
  107. // _loaderAnimation.handleProgress ( loadedWeightPercent, 1);
  108. }
  109. }
  110. }
  111.  
  112. /**
  113. * @param event BulkProgressEvent
  114. * when the swf loader is finished loading, add main.swf to the preloader stage
  115. * set vars in _mainMC needed for later
  116. */
  117. public function onAllItemsLoaded (event:Event): void {
  118. _mainMC = _assetLoader.getMovieClip("mainMC");
  119. _mainMC.registerLoader(_assetLoader);
  120. _mainMC.productSorter = _productSorter;
  121. addChild (_mainMC);
  122. }
  123.  
  124. }
  125. }
Add Comment
Please, Sign In to add comment