The Grey Labyrinth is a collection of puzzles, riddles, mind games, paradoxes and other intellectually challenging diversions. Related topics: puzzle games, logic puzzles, lateral thinking puzzles, philosophy, mind benders, brain teasers, word problems, conundrums, 3d puzzles, spatial reasoning, intelligence tests, mathematical diversions, paradoxes, physics problems, reasoning, math, science.

   
The Grey Labyrinth Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups    RegisterRegister  
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Flash MX Question

 
Reply to topic    The Grey Labyrinth Forum Index -> Off-Topic
View previous topic :: View next topic  
Author Message
Pi
Sir, I bear a rhyme ....



PostPosted: Wed Jun 11, 2003 10:27 am    Post subject: 1 Reply with quote

Any Flash MX users out there.

In flash there is a command to load an external .jpg file as shown

loadMovie("title.jpg",_root.hom)

If title does not exist and error message appears. Is there anyway of finding out if the file exists before loading it?

Back to top
View user's profile Send private message
Beartalon
'Party line' kind of guy



PostPosted: Wed Jun 11, 2003 1:24 pm    Post subject: 2 Reply with quote

http://news.flashguru.co.uk/?aid=000310

Try this. An explanation and the code for it as well.

Originally posted by The Article:

Checking if a file exists
Tuesday, 21st January, 2003

Sometimes it is necessary to determine if a file exists using actionscript, for example when you have a preloader cue, that loads a series of .jpgs one after another, if one of the files doesnt exist then the cue wouldnt traverse any further, you could of course use a timeout in that scenario but why not just check if the file exists before loading it, so that if necessary you can move onto the next item in the cue almost instantly. It is possible to determine whether a file exists using the success parameter of the onLoad event handler, the problem lies in the fact that the onLoad event handler for movieclips doesnt work, so to check if an .swf file exists, or an image, you will need to use this method...Here is a little example, that checks to see if a .swf file exists, and if it does, then it loads it into a movieclip.

fileExists=new LoadVars();
fileExists._parent=this;
fileExists.onLoad=function(success)
{
//success is true if the file exists, false if it doesnt
if(success)
{
//the file exists
var nm=this._parent.createEmptyMovieClip("swfHolder",1); //so create a movieclip
nm.loadMovie("myfile.swf"); //and load our .swf file into it
}
}
fileExists.load("myfile.swf") //initiate the test


You can do the same with any file type, even if flash doesnt support the loading of that filetype. You may also be wondering if the above process means you have to load a file twice, the answer is NO. If you are running you flash movie in the browser, then when you check to see if the file exists, the onLoad even handler wont fire until the file has fully downloaded into the browsers cache, but of course the Loadvars object wont do anything with an image file, sound file, or swf file. The next time round, when it comes to actually loading the file to actually display it(swf,image,text) or play it(sound) the file will load almost instantly from the browsers cache. If your flash movie is running on the local machine, then you dont have to worry about loading times anyway, because, as always the loading of a file locally is almost instant.


In the code above, I've fixed the syntax error that was pointed out in the comments.
The comments also say that this solution doesn't not work on a Mac, but it may have been just the machine used.
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Pi
Sir, I bear a rhyme ....



PostPosted: Wed Jun 11, 2003 3:09 pm    Post subject: 3 Reply with quote

did you get that to work?
Back to top
View user's profile Send private message
Beartalon
'Party line' kind of guy



PostPosted: Wed Jun 11, 2003 4:16 pm    Post subject: 4 Reply with quote

No, I just googled for it.
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Beartalon
'Party line' kind of guy



PostPosted: Wed Jun 11, 2003 4:16 pm    Post subject: 5 Reply with quote

I don't even know how to program Flash (yet)
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Pi
Sir, I bear a rhyme ....



PostPosted: Wed Jun 11, 2003 5:16 pm    Post subject: 6 Reply with quote

In that case thanks for you time and effort.

If you know abit of Java/C++ and a bit of VB, most flash is a doddle.

Back to top
View user's profile Send private message
Samadhi
+1



PostPosted: Wed Jun 11, 2003 11:22 pm    Post subject: 7 Reply with quote

I'm pretty good with VB and that code looks understandable.
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Beartalon
'Party line' kind of guy



PostPosted: Thu Jun 12, 2003 3:27 am    Post subject: 8 Reply with quote

To me as well, Samadhi. Just let us know if you get your project to work, Pi.
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Pi
Sir, I bear a rhyme ....



PostPosted: Thu Jun 12, 2003 9:20 am    Post subject: 9 Reply with quote

It ain't looking too hot so far . That code still kicks up an error window. I'll let you know when it's done.

If you are thinking of starting with Flash, my advice is do! It's powerful and fun and relatively easy to do some fancy stuff, the output file is really small and it's web compatible. What more do you want?

[This message has been edited by Pi (edited 06-12-2003 05:24 AM).]
Back to top
View user's profile Send private message
pikachamp
swore in chat!



PostPosted: Sun Jun 15, 2003 2:42 am    Post subject: 10 Reply with quote

flash me!
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Display posts from previous: by   
Reply to topic    The Grey Labyrinth Forum Index -> Off-Topic All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Site Design by Wx3