Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********************************************
- * Preloader
- *
- * Description: Loads all xml and swfs.
- * @author Paul Terhaar
- * @since 10-25
- * Copyright (C) 2008 Wirestone All Rights Reserved.
- *
- * -----------------------------------------
- * Change Log:
- * -----------------------------------------
- * date: by: description:
- * -- -- --
- *
- * -----------------------------------------
- ********************************************/
- package {
- import flash.display.MovieClip;
- import flash.events.Event;
- import com.stimuli.loading.BulkLoader;
- import com.stimuli.loading.BulkProgressEvent;
- import com.hp.kiosk.ProductSorter;
- public class Preloader extends MovieClip {
- // _mainMC is what the main swf is loaded into
- // typed as "*" because type is not known at compile time
- private var _mainMC:*;
- // BulkLoaders
- private var _XMLLoader:BulkLoader;
- private var _assetLoader:BulkLoader;
- // load vars
- private var _masterExternalBytesLoaded:Number = 0;
- private var _masterExternalBytesTotal:Number = 0;
- // this is where all xml and product/search arrays are stored
- private var _productSorter = new ProductSorter ();
- /**
- * Constructor
- */
- public function Preloader () {
- init ();
- }
- /**
- * Create loaders for xml and swfs
- */
- private function init ():void {
- // load the xml
- _XMLLoader = new BulkLoader ("XMLLoader");
- _XMLLoader.logLevel = BulkLoader.LOG_SILENT;; // LOG_SILENT, LOG_INFO, LOG_VERBOSE - set level to verbose, for debugging only
- _XMLLoader.add("assets/xml/printer_search.xml", {id:"printer_search", maxTries:10, priority:20});
- _XMLLoader.add("assets/xml/printer_details.xml", {id:"printer_details", maxTries:10, priority:20});
- _XMLLoader.add("assets/xml/computer_search.xml", {id:"computer_search", maxTries:10, priority:20});
- _XMLLoader.add("assets/xml/computer_details.xml", {id:"computer_details", maxTries:10, priority:20});
- _XMLLoader.add("assets/xml/search_options.xml", {id:"search_options", maxTries:10, priority:20});
- _XMLLoader.addEventListener(BulkLoader.COMPLETE, XMLLoaded);
- _XMLLoader.start ();
- // creates a BulkLoader instance with a name of "main-site", that can be used to retrieve items without having a reference to this instance
- _assetLoader = new BulkLoader("main-site");
- _assetLoader.logLevel = BulkLoader.LOG_SILENT; // LOG_SILENT, LOG_INFO, LOG_VERBOSE - set level to verbose, for debugging only
- _assetLoader.add("main.swf", { id:"mainMC", maxTries:10 } );
- _assetLoader.add("assets/video/TouchSmartII_1055x954.flv", { id:"demoVideo", maxTries:10, pausedAtStart:true } );
- _assetLoader.addEventListener(BulkLoader.PROGRESS, onAllItemsProgress);
- _assetLoader.addEventListener(BulkLoader.COMPLETE, onAllItemsLoaded);
- };
- /**
- * @param event BulkProgressEvent
- * When xml is loaded, store xml in _productSorter
- * then start the swf loader
- */
- private function XMLLoaded (event:BulkProgressEvent):void {
- // set xml document vars on productSorter
- _productSorter.printerSearchXML = _XMLLoader.getXML("printer_search");;
- _productSorter.printerDetailsXML = _XMLLoader.getXML("printer_details");;
- _productSorter.computerSearchXML = _XMLLoader.getXML("computer_search");;
- _productSorter.computerDetailsXML = _XMLLoader.getXML("computer_details");;
- _productSorter.searchOptionsXML = _XMLLoader.getXML("search_options");;
- // once the xml is loaded, load the other stuff
- _assetLoader.start();
- };
- /**
- * @param event BulkProgressEvent
- * This evt is a "super" progress event, it has all the information you need to
- * display progress by many criterias (bytes, items loaded, weight)
- * this function is currently unused.
- * if we were displaying a progress bar, this is where the preloader would be updated
- */
- private function onAllItemsProgress (event:BulkProgressEvent):void {
- _masterExternalBytesLoaded = event.bytesLoaded;
- _masterExternalBytesTotal = event.bytesTotal;
- var loadedWeightPercent = event.weightPercent;
- if (loadedWeightPercent != 0){
- if (loadedWeightPercent >= 1){
- // _loaderAnimation.handleComplete ();
- } else {
- // _loaderAnimation.handleProgress ( loadedWeightPercent, 1);
- }
- }
- }
- /**
- * @param event BulkProgressEvent
- * when the swf loader is finished loading, add main.swf to the preloader stage
- * set vars in _mainMC needed for later
- */
- public function onAllItemsLoaded (event:Event): void {
- _mainMC = _assetLoader.getMovieClip("mainMC");
- _mainMC.registerLoader(_assetLoader);
- _mainMC.productSorter = _productSorter;
- addChild (_mainMC);
- }
- }
- }
Add Comment
Please, Sign In to add comment