views:

63

answers:

3

I have an instance of URLLoader that works perfectly on my machine and a number of other machines, but in a few rare cases, regardless of the browser or the flash player version, URLLoader never comes back with any of my callbacks and so the load() method is fired off into the stratosphere and nothing happens beyond that.

Curious if anyone else has encountered this and if so how they got around it.

[EDIT]

Ok... never mind on the "no callbacks are fired". In fact it is firing the SecurityError.SECURITY_ERROR. However, I'm at a total loss as to why it would only fire this on some machines and not on others. Does it have something to do with the user's admin privileges or the browser's security settings? The error is 2170, phaseTwo (whatever that means)

[EDIT 2]

EUREKA!!! To www or not to www that is the question (or rather the answer). The issue had nothing to do with computers, but rather with the page being loaded without the www in some instances. Flash doesn't know what to do in that situation. Brilliant!

A: 

I have seen this error, but only when the uploading code was deferred by using another event. In my case I was using a MouseEvent.CLICK handler to generate the file to be uploaded then, once it was completed (ie. Another event listener) it would attempt to upload. The way i solved my issue was to have one click to generate the file, then when generated display another button whose click handler did the upload. But my problem showed up in all browsers. Are you sure you have the same flash player version in Safari as you do in the browsers that do work?

sberry2A
sorry, I just re-edited my question because the 2176 was a red herring that I was causing myself, on re-attempts. I had a timeout that attempted to re-upload if nothing happened after 5 seconds, but on initial attempt the error is not there (cause the mouse IS clicked) but the callbacks never fire. Thanks for your help though :)
Dr.Dredel
@sberry2A. The restriction you describe applies to FileReference objects. It could apply to URLLoaders only in the not so common case that you are posting content as multipart/form-data and the post body includes a filename attribute.
Juan Pablo Califano
that is actually precisely what I'm doing. Do you recommend a better way of uploading a file?
Dr.Dredel
+1  A: 

Three things come to mind that could cause this:

Make sure you are catching SecurityError.SECURITY_ERROR and IOError.IO_ERROR. If an error occurs, the COMPLETE event won't be raised.

If Loader is not added to the UI-tree, it won't work. If that's the case, you should be using URLLoader instead.

If you are adding the event listeners using addEventListener, make sure you are not using weak references. If you are, and aren't rooted, they could be garbage collected which would cause your symptoms.

Richard Szalay
@Richard Szalay. "If URLLoader is not added to the UI-tree, it won't work". What do you mean by that?
Juan Pablo Califano
It IS the SecurityError.SECURITY_ERROR!! Ok... but WTF?! Why is it only firing on some machines? What is that error connected to? (thanks a million for pointing me at it, I would never have thought to go catching it).
Dr.Dredel
@Dr.Dredel - Are you calling back to the same server, or are you calling back to a hardcoded server? If they are not the same, you'll need a `crossdomain.xml`. That includes the case where the user is accessing the site with a slightly different domain name (like without `www.`)
Richard Szalay
@Juan - If you create a URLLoader in actionscript and call load without adding the URLLoader as a child to another display object on the stage, the URLLoader will never fire any events.
Richard Szalay
@Richard Szalay. I disagree. I think perhaps you are confusing Loader and URLLoader (not sure if your assertion applies to Loaders; I don't think so either, but haven't tryed it). URLLoaders can't be added as children to other display object containers. Anyway, if I understood you right, you say the following shouldn't work. But it works:
Juan Pablo Califano
(cont) `public class StaticLoader { public static function load():void { var ld:StaticLoader = new StaticLoader(); ld.loadFile(); } public function loadFile():void { var loader:URLLoader = new URLLoader(); loader.addEventListener(Event.COMPLETE, function(e:Event):void { trace("complete")}); loader.addEventListener(IOErrorEvent.IO_ERROR, function(e:Event):void { trace("error")}); loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, function(e:Event):void { trace("error")}); loader.load(new URLRequest("http://s.ytimg.com/crossdomain.xml")); } }`
Juan Pablo Califano
If you call this in this way `StaticLoader.load();`, you'll see the loader fires the events. I don't think one could say this loader has been added to the display list.
Juan Pablo Califano
@Juan Pablo Califano - Apologies, I was confusing URLLoader and Loader. The added-to-stage requirement applies to `Loader`, not `URLLoader`
Richard Szalay
@Richard Szalay. No problem. I wasn't aware that Loaders had to be added to the stage to fire any events, so thanks for pointing it out. You learn something new every day!
Juan Pablo Califano
A: 

Without seeing code, from what you describe it seems that your loader could be collected before it fires any events. If your loader is stored in a local variable, try to move to a class instance variable (and perhaps seeing some code could help).

The above problem (which may or may not be the problem here) is not common in practice, in my experience, but it's definitely possible (I've seen this myself). I'm not sure under what exact circumstances it happens. I think an active loader will not be collected. But I'm not sure an active loader for the player is the same as an active loader from an Actionscript perspective. Meaning, from you AS code, an active loader would be a loader on which you have invoked the load method and has not yet finished loading (with or without errors). Now, for the player (again, this is a -hopefully educated- guess), active could mean something different. You can download only 2 assets from one domain simultaneously (a browser restriction); if you try to load more stuff, these operations are queued by the player. So maybe, a loader on which you have called load but has not actually begun the real loading, is not considered active by the player and so it's collectable.

Juan Pablo Califano
FYI, this scenario can't actually happen. Calling `load` on Loader / URLLoader roots them into the object graph. It's much more likely that weak references event handlers will be collected.
Richard Szalay
@Richard Szalay. I thought it couldn't happend, too. Until it happened to me. I only saw this in a case where I was running a bunch of loaders (and it only happened sometimes, if the GC happened to run). But if you have any links that prove the opposite I'd love to see them. The above is a guess as to *why* it happened, but it did happen to me and it wasn't weakref listeners (I never use them anyway).
Juan Pablo Califano
This is also easy to reproduce with FileReference objects (which is a different object, I know but is also part of the networking API). To my knowledge, the only objects that are not collectable even if they don't have AS references are *running* Timers.
Juan Pablo Califano