Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
bartpop

Double Loading

Recommended Posts

I'm working on an application and noticed that all of my SWF's were being loaded twice when I tested in the browser. I created a simplified model of my loader for testing purposes and found that my swf's were being double loaded there as well.

 

import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;

var _assetLoader:LoaderMax = new LoaderMax({name:"mainQueue"});
_assetLoader.addEventListener(LoaderEvent.COMPLETE, onAssetComplete);

_assetLoader.append(new SWFLoader("swf/test_swf.swf", {name:"testSWF"}));
_assetLoader.load();


function onAssetComplete(ev:LoaderEvent) : void {

_assetLoader.removeEventListener(LoaderEvent.COMPLETE, onAssetComplete);

var _test:MovieClip = _assetLoader.getContent("testSWF").rawContent;
addChild(_test);
}

 

I've manually created the LoaderEvent.COMPLETE listener because I need to replace the event handlers once the initial state of my app has loaded, but I suspect that LoaderMax is triggering it's own onComplete event listener by default and causing the double load. (or at least that's the best explanation that I could come up with).

 

http://labs.popstardigital.com/loaderMax/test_load.html

 

 

As the demo files don't exhibit the double-load behavior on my local machine I figured that there's an error in my implementation. I'm stumped. (UPDATE: I just realized that the demo files didn't include HTML files, so thought this could be embed code related?)

Link to comment
Share on other sites

I've run a series of tests but haven't located the cause of the double loading. I thought it might be a SWFObject related issue so I used the Flash-generated embedding code but still had the same problem.

 

http://labs.popstardigital.com/loaderMax/test_load_no_SWFObject.html

 

I also thought that it might be related only to loaders inside the main LoaderMax queue, so I added a SWFLoader outside of the mainqueue by adding this code to my original test.

 

var _swfLoader:SWFLoader =  new SWFLoader("swf/test_swf2.swf", {name:"testSWF2"});
_swfLoader.load();

addChild(_swfLoader.content);

 

It looks like only the SWF file inside the main LoaderMax queue is being double loaded.

 

http://labs.popstardigital.com/loaderMax/test_load2.html

 

I should mention that I'm testing in FireFox and Safari for Mac OS. Any ideas?

Link to comment
Share on other sites

I've been going through my tests with a fine toothed comb and here are the results:

 

FireFox is double loading the source SWF which is NOT being loaded by LoaderMax so that bug doesn't have anything to do with LoaderMax and most likely the known Bug 438830

 

Safari however seems to have a problem double loading files inside the main LoaderMax queue, whether using SWFObject or not. I'm running Flash Player version MAC 10.1.53.64, and LoaderMax 1.19

 

Safari 5.0

LoaderMax main queue. SWFObject 2.2

http://labs.popstardigital.com/loaderMax/test_load_SWFObject.html

Loads test_swf.swf twice (the file loaded by the main LoaderMax queue).

 

LoaderMax main queue. No SWFOject.

http://labs.popstardigital.com/loaderMax/test_load_no_SWFObject.html

Loads test_swf.swf twice (the file loaded by the main LoaderMax queue).

 

LoaderMax main queue. Separate SWFLoader. SWFObject 2.2

http://labs.popstardigital.com/loaderMax/test_load2_SWFObject.html

Loads test_swf.swf twice (the file loaded by the main LoaderMax queue).

Loads test_swf2.swf once (the file loaded by the separate SWFLoader).

 

LoaderMax main queue. Separate SWFLoader. No SWFOject.

http://labs.popstardigital.com/loaderMax/test_load2_no_SWFObject.html

Loads test_swf.swf twice (the file loaded by the main LoaderMax queue).

Loads test_swf2.swf once (the file loaded by the separate SWFLoader).

Link to comment
Share on other sites

OK, I ran one more test. I got rid of my manually added event listener, and even got rid of the code to add the content to the display object. The complete code is now:

 

import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;

var _assetLoader:LoaderMax = new LoaderMax({name:"mainQueue"});
_assetLoader.append(new SWFLoader("swf/test_swf.swf", {name:"testSWF"}));
_assetLoader.load();

 

In Safari, I can see that test_swf.swf is being loaded twice. If I replace the LoaderMax and append calls with a straight-up SWFLoader, the double loading goes away. You don't get any of the functionality of using a main loader queue though.

Link to comment
Share on other sites

The double loading appears to have been caused by auditSize defaulting to "true" in the LoaderMax constructor. Including "auditSize:false" in the parameters eliminated the double calls.

Link to comment
Share on other sites

The double loading appears to have been caused by auditSize defaulting to "true" in the LoaderMax constructor. Including "auditSize:false" in the parameters eliminated the double calls.

 

Exactamundo. As described in the documentation, by default LoaderMax will loop through all its children when it starts loading and if it finds any that don't have an estimatedBytes defined, it will open a URLStream momentarily to determine the bytesTotal of that file in order to make the overall reporting very accurate. So technically each file is requested twice but the first time doesn't load the files fully. As you discovered, you can easily disable this behavior with auditSize:false.

 

By the way, thanks for being so thorough in reporting back here as you made progress (or didn't). Sorry I couldn't respond sooner and save you some hassle.

Link to comment
Share on other sites

Sure thing Mr Green. Glad I got it figured out.

 

I should ask a couple of questions that came up while working through this. I read through the documentation on auditSize I came across this:

 

When the LoaderMax audits an XMLLoader, it cannot recognize loaders that will be created from the XML data nor can it recognize loaders inside subloaded swf files from a SWFLoader (it would take far too long to load sufficient data for that - audits should be as fast as possible). If you do not set an appropriate estimatedSize for XMLLoaders or SWFLoaders that contain LoaderMax loaders, you'll notice that the parent LoaderMax's progress and bytesTotal change when the nested loaders are recognized (this is normal).

 

In my application, I added a SWFLoader into my main LoaderMax queue to load a file called bgVideo.swf. Inside bgVideo.swf I have a VideoLoader with "requireWithRoot:this.root" and "estimatedBytes:1468000". When I add my bgVideo.swf file to the main LoaderMax queue using SWFLoader, the VideoLoader load was not being included in my LoaderMax queue's progress.

 

I'm trying to understand the documentation correctly. Is it the case that LoaderMax doesn't look inside SWF files added to through SWFLoader for other Loaders, or is that only the auditSize function? Is there any way to include my SWF file's VideoLoader progress as part of the SWF files' total load? I tried setting the SWFLoader's estimatedBytes to include the size of the SWF plus the size of the video file but that didn't appear to force the VideoLoader to be included in the SWF file's load bundle. In my case the video file would start loading, but the main queue would dispatch it's onComplete long before the video file had finished loading.

 

I created a workaround by manually adding the VideoLoader to the main queue, but automatically bundling the loads nested inside SWFs would be so very cool.

Link to comment
Share on other sites

I had to raise one more question. After reading this again:

By default, when the LoaderMax begins to load it quickly loops through its children and if it finds any that don't have an estimatedBytes defined, it will briefly open a URLStream in order to attempt to determine its bytesTotal, immediately closing the URLStream once the value has been determined.

I set the estimatedBytes on all of my Loaders, but it looks as if my files were being audited anyway (I was seeing double loads). The strangest issue I noticed while monitoring the double file loads in my browser was that when I used a relative path to my video file in VideoLoader, the first call to the file (auditSize call) would use the correct path. During the second call (the actual load) the path had changed (was moved up one folder relatively), causing the file to not be found. Once again, I solved the issue by manually setting the auditSize:false in my LoaderMax queue but thought I should report the issue.

Link to comment
Share on other sites

Hmm, sounds like there may be something else going on in your file(s).I cannot fathom why the audit load would use a different URL (feel free to look at the source - you'll see that they both use the same one). And yes, to answer your earlier question, the SWFLoader will indeed look for other loaders inside the subloaded swf so it should find your VideoLoader and integrate it into the progress (unless you set integrateProgress:false of course). And increasing your SWFLoader's estimatedBytes to include the VideoLoader's size should indeed prevent any jumping forward and then back of the progress. And if you set estimatedBytes on all your loaders, there's no reason why it'd be doing audits resulting in double-loads. All this to say: I'd REALLY like to get my hands on a simple example FLA (or set of FLAs) that demonstrates the issues you're running into. I'm pretty sure something else must be going awry in there. You are using the latest versions of all the classes, right? http://www.LoaderMax.com

Link to comment
Share on other sites

For the record, I'm using LoaderMax version 1.19. The app I'm building relies on a pretty extensive library of classes so it becomes difficult to share the exact code I'm using. Time permitting I'll work on building out a simplified model. Pesky deadlines seem to get in the way of everything. ;)

 

Not having gone through the inner workings of the LoaderMax classes, I've got a couple of theories as to what's going on with some of the problems I'm experiencing.

 

As far as the relative paths go, I've got a class that helps set the relative path based on whether the swf is being viewed in a browser or in the standalone player, by referencing the Capabilities.playerType. The playerType seems to have switched somewhere between the VideoLoader auditing and loading functions, causing the difference in the relative paths.

 

I don't know the details of how LoaderMax audits the child SWFs looking for nested Loaders, but came up with a theory on why the VideoLoader wasn't being included while watching the file loading activity. Initially with maxConnections:2 I could fairly easily watch which files were being added to the loader. When I saw my 35k SWF file start loading, it appears to have finished loading before the video even got added to the queue. My theory is that the main LoaderMax queue loaded the SWF file so quickly, that it thought that it had finished and fired the onComplete event before it knew there was a nested loader inside the SWF. Tracing through my code, the video file would have been the last file added to the queue; nested inside the last SWF added. Possible?

 

I tried increasing the maxConnections to 5, hoping that another process would give LoaderMax the time to detect the nested VideoLoader but that wasn't successful.

Link to comment
Share on other sites

No, you shouldn't need to worry about timing issues like that - SWFLoader won't dispatch its COMPLETE event until it has looked in the swf for other loaders. Are you somehow delaying the creation of that nested VideoLoader? As long as you're creating it in your main class or on the first frame of that subloaded swf, you're fine. And of course make sure that requireWithRoot is set to that swf's root. Maybe you mistyped that?

 

If you send me a sample FLA that I can simply publish and investigate, I can identify the issue much more quickly.

Link to comment
Share on other sites

Just about every class I write includes code in the constructor that delays the construction of the object until the it's added to the stage.

 

	if (!stage) {
		this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
	} else {
		init();
	}

 

I guess that what's obscuring the VideoLoader from LoaderMax? I have to admit, I've never worked with a class that parses through nested swf's before they're added to the display object and I really don't know how LoaderMax works it's magic. I'll try moving the creation of the videoLoader ahead of the pause in the constructor and see if that solves the problem.

Link to comment
Share on other sites

Yep, that probably is exactly what the problem is. When your swf loads, that's when SWFLoader looks for LoaderMax-related loader instances inside the swf. If you haven't created them yet, it obviously won't be able to find them :) So yeah, create your VideoLoader instance in your sub-swf's main class file's constructor or on the first frame of that swf or something so that the VideoLoader exists when SWFLoader tries hunting for it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×