Preloaders with multiple files?

  • nornholdj
  • Novice
  • Novice
  • User avatar
  • Posts: 18

Post 3+ Months Ago


I have two .fla files. One is my preloader and the second is my main swf for the rest of the website. My preloader of course loads my main swf by showing a bar displaying the percentage of what has loaded. My main.swf in turn also loads a few xml files to display the information contained in them. I tried loading the xml files inside the preloader and I think it loads but when I go to the section of my main movie that uses that xml it throws an error that says: "Cannot access a property or method of a null object reference". I assume thats because I try to reload it in my main movie. I'm just not sure how I should go about it. I'm also unsure of how I can add up the total values of both files for the progress bar. I'm using AS3 with CS3 and here is my code.

Code: [ Select ]
var websiteLoader:Loader = new Loader();
websiteLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, websiteLoading);
websiteLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, websiteLoaded);    
websiteLoader.load(new URLRequest("main.swf"));

websiteLoader.load(new URLRequest("xml/MSPInfo.xml"));

function websiteLoading(e:ProgressEvent):void
    var loaded:Number = e.bytesLoaded / e.bytesTotal;
    pLoaded.text = Math.ceil(loaded * 100) + " % Loaded";
    //trace(e.bytesLoaded + "/" + e.bytesTotal);

function websiteLoaded(e:Event):void
    pLoaded = null;
    preloader.visible = false;
    preloader = null;
  1. var websiteLoader:Loader = new Loader();
  2. websiteLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, websiteLoading);
  3. websiteLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, websiteLoaded);    
  4. websiteLoader.load(new URLRequest("main.swf"));
  5. websiteLoader.load(new URLRequest("xml/MSPInfo.xml"));
  6. function websiteLoading(e:ProgressEvent):void
  7. {
  8.     var loaded:Number = e.bytesLoaded / e.bytesTotal;
  9.     pLoaded.text = Math.ceil(loaded * 100) + " % Loaded";
  10.     preloader.SetProgress(loaded);
  11.     //trace(e.bytesLoaded + "/" + e.bytesTotal);
  12. }
  13. function websiteLoaded(e:Event):void
  14. {
  15.     removeChild(pLoaded);
  16.     removeChild(longLogo);
  17.     removeChild(preloader);
  18.     //removeChildAt(0);
  19.     pLoaded = null;
  21.     preloader.visible = false;
  22.     preloader = null;
  23.     addChild(websiteLoader);
  24. }

Code: [ Select ]
//setup loading for xml page with MSP data
var MSPLoader:URLLoader = new URLLoader();
var MSPRequest:URLRequest = new URLRequest("xml/MSPInfo.xml");
MSPLoader.addEventListener(Event.COMPLETE, loadData);
var MSPDoc:XML;
  1. //setup loading for xml page with MSP data
  2. var MSPLoader:URLLoader = new URLLoader();
  3. var MSPRequest:URLRequest = new URLRequest("xml/MSPInfo.xml");
  4. MSPLoader.load(MSPRequest);
  5. MSPLoader.addEventListener(Event.COMPLETE, loadData);
  6. var MSPDoc:XML;


  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1825
  • Loc: In the Great White North

Post 3+ Months Ago

Code: [ Select ]
websiteLoader.load(new URLRequest("main.swf"));

websiteLoader.load(new URLRequest("xml/MSPInfo.xml"));
  1. websiteLoader.load(new URLRequest("main.swf"));
  2. websiteLoader.load(new URLRequest("xml/MSPInfo.xml"));

these two lines are fighting because your using the same loader object for both of them at the same time. So technically your replacing the load command a millisecond after you call it the first time.

I would wait to call the xml file until the other call has finished either in the callback for the loader you have or via a completely new loader object if you need the xml at the same time as the main movie load.

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 5 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum

© 1998-2017. Ozzu® is a registered trademark of Unmelted, LLC.