Alright...

I have a minute now...

This may be an issue of semantics, but if what we want to know is whether the file exists or not on an HTTP connection, then the only way is to wait for the success boolean. HTTP servers do respond when a requested resource is not available. This is the classic 404 HTTP status. Unfortunately there is no way of knowing if the response coming back from the server is the requested resource or an Error type HTTP response until the response is downloaded and we can either see the HTTP response headers (flash 8) or test the success boolean. The only other possible condition is whether the resource requested, existing or not, is available. By this I mean whether the connection to the server was achieved and the request is processed in "reasonable" time. This is where a time out comes in. I think time out subjectivity can be minimized by testing for the first few bytes, not whether the full response happens or not. There is a huge difference if we give 10 seconds to get a full response to a 50K file or the same 10 seconds to just test the first few bytes of the same file.

In other words... if in 10 seconds you have not loaded a single byte, then forget it, the response is either not coming or too slow. On the other hand, if you did get a single byte on those 10 seconds, then you are going to have to wait for the full response to find out whether that response indicates that the resource exists or not.

Again, to that effect:

//-------------------- code --------------------------
function fileExists() {}
function fileDoesNotExist() {}

var timeout:Number = 10000; // 10 seconds...
var app:MovieClip = this;

var lv:LoadVars = new LoadVars();
lv.onLoad = function(success:Boolean) {
        clearInterval(app.interval);
        if (!success) {
                app.fileDoesNotExist();
        } else {
                app.fileExists();
        }
};

var startTime:Number = getTimer() + timeout;
lv.load(url);

var interval:Number = setInterval(function () {
        var loaded:Number = app.lv.getBytesLoaded();
        if (loaded == 0 && getTimer() >= app.startTime) {
                app.lv.onLoad = null;
                delete app.lv;
                clearInterval(app.interval);
                app.fileDoesNotExist();
        } else if(loaded > 0) {
                clearInterval(app.interval);
        }
}, 25);
//-------------------- code --------------------------

This essentially tests whether a there has been no response in the given timeout. If there hasnt it clears out. If on the other hand, there has, it waits for the load to determine whether the file exists or not.

I think only a simple server side proxy script, or perhaps even an AJAX script, could bypass the hassle of waiting for the full response.



On Mar 18, 2006, at 6:53 AM, Ian Thomas wrote:

Bart,
  Firstly, I'm not sure why that's a reply to my posting - and
secondly, why would you want to do that..?

  The original poster asked if there was a way of checking whether a
file exists sooner than waiting for the whole file to load. Your
solution loads the whole file via LoadVars - which would take the same
amount of time as loading it normally. My solution is a quick call to
a webserver and a few bytes worth of response - much quicker than
(say) loading a 250Kb file...

Ian

On 3/18/06, Bart Wttewaall <[EMAIL PROTECTED]> wrote:
Ian: "There's no Flash native hack as far as I know."

You can check (and cache while you're at it) any file by using LoadVars:

var file:String = "anyFileType.exe";

var fileExists:LoadVars = new LoadVars();
fileExists.onLoad = mx.utils.Delegate.create(this, doCheck);
fileExists.load(file);

function doCheck(success:Boolean) {
        if (success) trace("File "+file+" exists.");
        else trace("File "+file+" does not exist.");
}


_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to