ActionScript: how to determine the type of loaded content?
I have a situation where I load some content using a URLLoader, but the content can be either video (flv or swf), or image (jpg or png or gif), or swf. The trick is that I need to react differently depending on the type of content being loaded, without knowing what type of content it is in advance.
Currently I have come up with a tricky solution (and by design I mean a convoluted sequence of if and try ... catch blocks) involving either trying to load it into the control and catch errors (ex: I will create an Image instance, add a listener events for the ioError event and get it, I'm guessing it's not an image or swf ...) but it looks like a hack.
Is there any clean way to determine the type of uploaded content from the URLLoader?
source to share
Take a look at: http://code.google.com/p/as3httpclient/wiki/Links to determine the response headers. I've used it for other purposes and it worked well.
source to share
Unfortunately, it looks like if you're not using AIR, then you don't have (at least today) access to the HTTP response headers (i.e. URLLoader.httpResponseStatus). So your "contrived" approach (which I actually used myself!) Is probably as appropriate for the time being as the previous poster is.
It looks like there is an open issue for Adobe:
http://bugs.adobe.com/jira/browse/FP-251
... so at least there is that. :)
source to share