Re: [Flashcoders] File Exists - a better way?
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 = 1; // 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."); } ___ Flashcoders@chattyfig.figleaf.com 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 ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] File Exists - a better way?
Ah, you're right Ian. My post wasn't really a reply to your sollution, the topic "File Exists - a better way" just triggered a memory to the code I posted. I just wanted to contribute a bit to the original topic (it was a long, tiresome day). But perhaps it might be useful in some other way? For example if you'd like to preload/cache a few files when your application starts that can be used later on... Oh well, sorry for the noise. Bart 2006/3/18, Ian Thomas <[EMAIL PROTECTED]>: > 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."); > > } > > > > > ___ > Flashcoders@chattyfig.figleaf.com > 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 > ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] File Exists - a better way?
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."); > } > > ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] File Exists - a better way?
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."); } 2006/3/18, Isaac Rivera <[EMAIL PROTECTED]>: > I backtracked on this thread... > > I guess the questions are: > > 1) what are you trying to load? > > 2) what onLoad(success:Boolean) are you using? > > Are you using the XML or LoadVars? > > Assuming you are using the LoadVars, a more reasonable "timeout" > approach would be something like: > > // code -- > function fileExists() {} > function fileDoesNotExist() {} > > var timeout:Number = 1; // 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 total:Number = app.lv.getBytesTotal(); > if (total > 4) { > clearInterval(app.interval); > app.fileExists(); > } else { > if (getTimer() >= app.startTime) { > clearInterval(app.interval); > app.fileDoesNotExist(); > } > } > }, 25); > > // code -- > > > On Mar 17, 2006, at 10:31 AM, Yotam Laufer wrote: > > > [Theres no "reasonable" amount of time on networked connections of > > unknown hardware specs...] > > > > And yet timeout times are set somehow... I think it's a subjective > > decision. > > I wouldn't do it like this, but if someone has to? > > > > Yotam. > > ___ > > Flashcoders@chattyfig.figleaf.com > > 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 > > ___ > Flashcoders@chattyfig.figleaf.com > 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 > ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] File Exists - a better way?
I backtracked on this thread... I guess the questions are: 1) what are you trying to load? 2) what onLoad(success:Boolean) are you using? Are you using the XML or LoadVars? Assuming you are using the LoadVars, a more reasonable "timeout" approach would be something like: // code -- function fileExists() {} function fileDoesNotExist() {} var timeout:Number = 1; // 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 total:Number = app.lv.getBytesTotal(); if (total > 4) { clearInterval(app.interval); app.fileExists(); } else { if (getTimer() >= app.startTime) { clearInterval(app.interval); app.fileDoesNotExist(); } } }, 25); // code -- On Mar 17, 2006, at 10:31 AM, Yotam Laufer wrote: [Theres no "reasonable" amount of time on networked connections of unknown hardware specs...] And yet timeout times are set somehow... I think it's a subjective decision. I wouldn't do it like this, but if someone has to? Yotam. ___ Flashcoders@chattyfig.figleaf.com 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 ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] File Exists - a better way?
[Theres no "reasonable" amount of time on networked connections of unknown hardware specs...] And yet timeout times are set somehow... I think it's a subjective decision. I wouldn't do it like this, but if someone has to? Yotam. ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] File Exists - a better way?
Theres no "reasonable" amount of time on networked connections of unknown hardware specs... Have you looked into onData instead? I believe it will allow you to know if the file exists bases on the first packet of the response. Isaac Rivera Senior Flash Developer Audience Programming, America Online On Mar 17, 2006, at 9:14 AM, Yotam Laufer wrote: If onload fires immediately with success==false then you know that there's no file, so why don't you wait for a reasonable interval and then if it's not fired than assume the file exists. not the best of solutions but should work. Yotam ___ Flashcoders@chattyfig.figleaf.com 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 ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] File Exists - a better way?
_mc.onLoad = function (success) { if (success) { trace ("file loaded"); } else { _global.fileExists = false; } }; _gloabl.fileExists = true; _mc.loadMovie (url); // wait 250 ms and see whether the file has failed var intId = setInterval (function () { if (_global.fileExists) { trace ("file exists"); } else { trace ("no file"); } clearInterval (intId); }, 250); This is not tested, but should work. The only penalty is the the time you have to wait to be sure. Yotam. ___ Flashcoders@chattyfig.figleaf.com 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
RE: [Flashcoders] File Exists - a better way?
I think because if the file exists, you will have to wait till the file has loaded completely before you know about it. Adrian -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Andreas Rønning Sent: 17 March 2006 15:04 To: Flashcoders mailing list Subject: Re: [Flashcoders] File Exists - a better way? It stands to reason that if onLoad fires with success==false no file was loaded anyway, so i don't see why you'd need a separate handler for wether success is false NOW or success is false a little later. onLoad(success){ if(success){ //handle file load }else{ //handle error } } I don't see the downside to this approach. Then again, i'm tired and angry, so i might miss something. - A Yotam Laufer wrote: > If onload fires immediately with success==false then you know that there's > no file, so why don't you wait for a reasonable interval and then if it's > not fired than assume the file exists. not the best of solutions but should > work. > > Yotam ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] File Exists - a better way?
It stands to reason that if onLoad fires with success==false no file was loaded anyway, so i don't see why you'd need a separate handler for wether success is false NOW or success is false a little later. onLoad(success){ if(success){ //handle file load }else{ //handle error } } I don't see the downside to this approach. Then again, i'm tired and angry, so i might miss something. - A Yotam Laufer wrote: If onload fires immediately with success==false then you know that there's no file, so why don't you wait for a reasonable interval and then if it's not fired than assume the file exists. not the best of solutions but should work. Yotam ___ Flashcoders@chattyfig.figleaf.com 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 -- - Andreas Rønning --- Flash guy Rayon Visual Concepts, Oslo, Norway --- ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] File Exists - a better way?
There's no Flash native hack as far as I know. The only obvious solution I can think of is to call a server script - for example in PHP something like: Then use LoadVars to call the script, passing in the parameter 'file' - which is a filename relative to the PHP script. Once LoadVars returns, if the 'exists' parameter is false, the file doesn't exist - and so on. HTH, Ian On 3/17/06, Wendy Richardson <[EMAIL PROTECTED]> wrote: > I know I can find if a file I want to load exists by using "onload" with > "success", but there must be something more immediate. Using onload, I > can'd determine success answer untill the file is completely loaded > which is too long for my purposes. Anyone have a hack for determining > if a file exists? > > Thanks > > Wendy ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] File Exists - a better way?
If onload fires immediately with success==false then you know that there's no file, so why don't you wait for a reasonable interval and then if it's not fired than assume the file exists. not the best of solutions but should work. Yotam ___ Flashcoders@chattyfig.figleaf.com 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
RE: [Flashcoders] File Exists - a better way?
Do you have access to a scripting language on the server where the file resides? If you do, get that to do the check for if the file exists and interrogate that instead. Maybe. Adrian -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Wendy Richardson Sent: 17 March 2006 14:06 To: flashcoders@chattyfig.figleaf.com Subject: [Flashcoders] File Exists - a better way? I know I can find if a file I want to load exists by using "onload" with "success", but there must be something more immediate. Using onload, I can'd determine success answer untill the file is completely loaded which is too long for my purposes. Anyone have a hack for determining if a file exists? Thanks Wendy ___ Flashcoders@chattyfig.figleaf.com 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
[Flashcoders] File Exists - a better way?
I know I can find if a file I want to load exists by using "onload" with "success", but there must be something more immediate. Using onload, I can'd determine success answer untill the file is completely loaded which is too long for my purposes. Anyone have a hack for determining if a file exists? Thanks Wendy ___ Flashcoders@chattyfig.figleaf.com 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