×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Detect proper file format?

Detect proper file format?

Detect proper file format?

(OP)
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.


RE: Detect proper file format?

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 baFileType() function to determine the file type, but this is only for Mac.

I would actually use Buddy API baGetFilename() to get the file name instead of using MUI fileOpen(). baGetFilename() 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
www.materiaprima.co.uk

RE: Detect proper file format?

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close