Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
Wait for SWA Member finishes Playing(sprite as reference)
Icon Shop
TAGGuard
Projector debugger
simPPTViewer1.0 Xtra
Linking 1 sprite to another by location
Light Up
Preload Frames
Irregular MIAW
Lingo Paradise Tutorials
 

 

 

Behavior Get Dropped Files

Added on 10/2/2000

 

Compatibilities:
behavior D7 D8 PC

Required Xtras:
Drop File

This item has not yet been rated

Author: MediaMacros (website)

This script allows you to detect if the user drags a certain type of file onto a sprite and then deals with the data as you see fit.

--This script allows you to detect if the user drags a certain type of file onto a sprite and then deals with the data as you see fit.  Note that it requires the freeware dropFile Xtra by Gary Smith and the Drop Files setup scripts must also be added to your existing startMovie and stopMovie handlers. The basic options are as follows...
--The first field allows input of 3 letter file types.  Separate them with commas and NO spaces!!
--The next option is what to do with the returned list.  You can run a handler with the data, save to a global, append a global, save to a field, or append a field.
--The use folders check box enables/disables the program recognizing and passing folders.  Note that folders will be passed in a different variable and launched in another instance of a handler.
--Check the next box to make handlers run with each file rather than the whole list.
--The last option is the supporting command for the chosen type...
--Do action - this is the handler with the word variable where the list or item should be passed back.  Example - myHandler(variable)
--Globals and fields work similar here.  Just input the names for the file and the folder globals or field anmes separated by a comma (no spaces) like so...myFiles,myFolders

property spriteNum, filetypes, whatPutInto, subCommand, oneOrMore, useFolders

on getPropertyDescriptionList me
  p_list = [:]
  addProp p_list, #fileTypes, [#format : #string, #default : "tif,gif,jpg", #comment : "What file types to accept: (separate with commas.  Leave blank for all.)"]
  addProp p_list, #whatPutInto, [#format : #symbol, #default : #doAction, #comment : "What to do with the dropList:", #range : [#doAction, #saveToGlobal, #addToGlobal, #replaceField, #addToField]]
  addProp p_list, #useFolders, [#format : #boolean, #comment : "Should folders be used if dropped?", #default : true]  
  addProp p_list, #oneOrMore, [#format : #boolean, #comment : "Run for each item in the list? (For doAction will run the handler with each item rather than the whole list, for fields and globals - no effect.):", #default : true]
  addProp p_list, #subCommand, [#format : #string, #default : "baOpenFile(variable, " & quote &"normal""e&")", #comment : "Enter in a sub command.  For doAction enter a handler and use the work variable to replace the returned value, for globals enter a globalname(if you use folders, enter a second one for the folders separated by a comma), and for fields enter the field name(or 2 for folders.)"]  
  return p_list
end

on doDrop me
  if inside(point(the mouseH, the mouseV), sprite(spriteNum).rect) then
    fileList = getDroppedFiles()
    folderList = getDroppedFolders()
    --set list of legal items
    the itemDelimiter = ","
    okList = []
    if fileTypes <> "" then
      repeat with a = 1 to fileTypes.item.count
        numChar = fileTypes.item[a].char.count
        if numChar < 3 then
          add okList, fileTypes.item[a]
        else
          startNum = (numChar-2)
          add okList, fileTypes.item[a].char[startNum..numChar]
        end if
      end repeat  
    end if  
    --clean out illegal files
    the itemDelimiter = "."
    if fileTypes <> "" then
      if fileList.count >= 1 then
        repeat with x = fileList.count down to 1
          extension = fileList[x].item[fileList[x].item.count]
          if getOne(okList, extension) = 0 then
            deleteAt fileList, x
          end if
        end repeat
      end if
    end if
    --createStrings
    fileString = ""
    folderString = ""
    if fileList.count >= 1 then
      repeat with y = 1 to fileList.count
        fileString = fileString & fileList[y]
        if y < fileList.count then
          fileString = fileString & return
        end if
      end repeat
    end if
    if folderList.count >= 1 then
      repeat with y = 1 to folderList.count
        folderString = folderString & folderList[y]
        if y < folderList.count then
          folderString = folderString & return
        end if
      end repeat
    end if
    --send the data
    case whatPutInto of
      #doAction:
        commandChar = offset("variable", subCommand)
        commandStart = subCommand.char[1..(commandChar-1)]
        commandEnd = subCommand.char[commandChar + 8..subCommand.char.count]
        if oneOrMore = true then  
          if fileList.count >= 1 then
            repeat with z = 1 to fileList.count
              do commandStart & quote & fileList & quote & commandEnd
            end repeat
          end if
        else
          do commandStart & "fileList" & commandEnd
        end if
        if useFolders = true then
          if oneOrMore = true then  
            if folderList.count >= 1 then
              repeat with z = 1 to folderList.count
                do commandStart & quote & folderList & quote & commandEnd
              end repeat
            end if
          else
            do commandStart & "folderList" & commandEnd
          end if
        end if      
      #saveToGlobal,#addToGlobal:
        the itemDelimiter = ","
        fileGlobal = subCommand.item[1]
        if subCommand.item.count > 1 then
          folderGlobal = subCommand.item[2]
        else
          folderGlobal = ""
        end if
        if whatPutInto = #saveToGlobal then
          put fileList
          setAProp (the globals), symbol(fileGlobal), fileList
          put value(fileGlobal)
        else
          newList = value(fileGlobal)
          if fileList.count >= 1 then
            repeat with b = 1 to fileList.count
              add newList, fileList[b]
            end repeat
          end if
          setAProp (the globals), symbol(fileGlobal), newList
        end if
        if useFolders = true and folderGlobal <> "" then        
          if whatPutInto = #saveToGlobal then
            setAProp (the globals), symbol(folderGlobal), folderList
          else
            newList = value(folderGlobal)
            if folderList.count >= 1 then
              repeat with b = 1 to folderList.count
                add newList, folderList[b]
              end repeat
            end if
            setAProp (the globals), symbol(folderGlobal), newList
          end if
        end if      
      #replaceField, #addToField:
        fileMember = subCommand.item[1]
        folderMember = subCommand.item[2]        
        
        if fileMember <> "" and the number of member(fileMember) > 0 then
          if member(fileMember).type = #field or  member(fileMember).type = #text then
            if whatPutInto = #replaceField then
              member(fileMember).text = fileString
            else
              member(fileMember).text = member(fileMember).text & return & fileString
            end if            
          end if
        end if
        if useFolders = true then
          if folderMember <> "" and the number of member(folderMember) > 0 then
            if member(folderMember).type = #field or  member(folderMember).type = #text then
              if whatPutInto = #replaceField then
                member(folderMember).text = folderString
              else
                member(folderMember).text = member(folderMember).text & return & folderString
              end if  
            end if
          end if
        end if        
    end case
  end if
end

on getBehaviorDescription me
  describe = "This script allows you to detect if the user drags a certain type of file onto a sprite and then deals with the data as you see fit.  Note that it requires the freeware dropFile Xtra by Gary Smith.  (www.mods.com.au) and the acompanying scripts must also be added to your existing startMovie and stopMovie handlers. The basic options are as follows..." & return & "The first filed allows input of 3 letter file types.  Separate them with commas and NO spaces!!" & return & "The next option is what to do with the returned list.  You can run a handler with the data, save to a global, append a global, save to a field, or append a field." & return & "THe use folders check box enables/disables the program recognizing and passing folders.  Note that folders will be passed in a different variable and launched in another instance of a handler." & return & "Check the next box to make handlers run with each file rather than the whole list." & return & "The last option is the supporting command for the chosen type..." & return & "Do action - this is the handler with the word variable where the list or item should be passed back.  Example - myHandler(variable)" & return & "Globals and fields work similar here.  Just input the names for the file and the folder globals or field anmes separated by a comma (no spaces) like so...myFiles,myFolders"
  return describe
end

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail