Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect proper file format?

Status
Not open for further replies.

gcarcass

MIS
Jul 16, 2005
8
0
0
JP
Hello!! Uf!!! Finally I"m about to finish this "bloody" project which has caused me nothing but blood, sweat and tears. (but also I've learned a lot!)

I'm using this script attached to a button to load external images into the cast :

on mouseUp me

set MUIobject = new(xtra "MUI")
result = fileOpen(MUIObject,"Xtras")

MUIObject = 0

importFileInto member(5), result
sprite(115).member = member (5)
member(5).name = "image1"

sprite(115).height = 252
sprite(115).width = 252

end

I want to load only images, I would like to add some lines(I hope just a few) in order to reduce the amount of "allowed" kind of files. Basically I would like to prevent that a wrong format might be loaded, for example when somebody tries to load a WAV or AIFF(among others) file instead of a JPG by mistake(Yeah, I know! who da' hell would do that mistake, but it does happen!) the projector return a message like "sorry you are trying to load an incorrect file format, please try with another one" or something like that.

Links, suggestion, opinions, comments, and mostly help will be appreciated.

Thanks in advance.


 
You have to rely on the file extension i.e. ".JPG". This will not filter out the files with wrong extension, e.g. a WAV file with .JPG extension, but you have to live with that.

On Mac you can use Buddy API [tt]baFileType()[/tt] function to determine the file type, but this is only for Mac.

I would actually use Buddy API [tt]baGetFilename()[/tt] to get the file name instead of using MUI [tt]fileOpen()[/tt]. [tt]baGetFilename()[/tt] offers far better control over the dialogue box. For example you can set it to display only .JPG files - this is basically what you want!

Kenneth Kawamoto
 
Finally, this is working perfect!!! Thanks to TonyDomigan from DOMAJ Forum. And Steve Karmen from Director Online. Thanks a lot, actually I used Steve advice and it worked but using FileXtra4, but I prefer to go on a solution because the filtering in FileXtra4 does not work 100% ok. Rather go for the old fashion Alert Windows. Thanks a lot!!


on pointerLoad me

set MUIobject = new(xtra "MUI")

--| change
theDirectory = "Xtras"
result = fileOpen(MUIObject,theDirectory)

MUIObject = 0

resCount = result.char.count
fileExt = result.char[resCount - 2..resCount]

if fileExt = "swf" then

importFileInto member(55), result

sprite(167).member = member(55)

sprite(167).height = 71
sprite(167).width = 71

else
--| change
if result<>theDirectory then
alert "Wrong file format.Only Flash files(*.swf) are allowed."
end if

end if

end
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top