Importing PICTs

>I'd like to do something similar.  I have a single frame in which
>I page through a large number of PICTs.  I'd like to avoid having
>those PICTs in my cast.  Instead I'd like to read the files from disk
Here are a couple of approaches; the first two assume that you do not need to worry about palettes.

APPROACH 1

  1. Create a PICT castmember (a small black square will do). Name this castmember, e.g., "thePICT". This will serve as a placeholder in the cast for your imported PICTs.
  2. Create a handler like the following and pass it the name of the file you want to import.
    on importPICTFile whichFile
      set x=the number of cast "thePICT"
      set the filename of cast "thePICT" to "@:" & whichFile
      set the name of cast x="thePICT"
    end
    Note 1: you can use THE PATHNAME function instead of "@:" See pgs 52-54 of the "Tips & Tricks" manual that came with Director for more info on pathnames, relative pathnames, and use of the '@' symbol.

    NOTE 2: If you choose to refer to the castmember containing your PICT by number (i.e., if you won't be moving it around in the cast window) then you do not need the 1st and last lines shown above. The reason they are needed here is that when you import the file the castmember containing the PICT gets renamed by Director to the name of the imported file. Thus the next time you call importFile there will not be a cast called "thePICT" and you will get an error message. :-(

  3. Go to a frame that contains the castmember "thePICT". Note that the imported castmember will be centered on the screen to the same location as the original castmember (assuming your registration point is centered for the placeholder PICT).

    APPROACH 2 (using mReadPICT method)

    mReadPICT the advantage that you can do more error checking via the error codes that are returned by the fileIO xObj. You can see a list of these error codes by typing fileIO(mDescribe) in the message window of Director (Note that mReadPICT is UNDOCUMENTED and you won't find any information about it using mDescribe).
    on importPICTFile whichFile
      global fileIO,pictFile
      if objectP(pictFile) then pictFile(mDispose)
      put FileIO(mNew,"read",the pathname &whichFile) into pictFile
      if objectP(pictFile) then
       set the picture of cast "thePICT" to pictFile(mReadPICT)
      else if pictFile=-43 then
      
      -- file not found; see fileIO error codes for more possible error codes
        alert "File not found: '" & whichFile
      else
        ...whatever...
      end if
      pictFile(mDispose)
    end

    APPROACH 3 (with palettes)

    When Director imports a PICT file using the above methods, it DOES NOT import the custom palette (if any) associated with the PICT file. Instead, the file is remapped to whatever palette is current active in your project. Thus, you must change the active palette to whatever palette is to be used by the imported PICT before doing the import! The example below assumes that you have already set the appropriate palette on the stage before importing the file.

    I generally create two lists, one with the filenames of the PICTs available for importing (you can include the pathname as part of each list entry; if you don't store this info in the file list than you will need to modify the importFile handler to include pathname info for your PICT), and another list with their associated palettes (palettes are stored as castmembers). The lists are in the same order (i.e., 3rd palette in paletteArray is associated with the 3rd file in the file list).In this example you pass the appropriate list entry (i.e., which item on the list) to the importFile handler as arrayIndex. Remember, this example assumes you have already set the appropriate palette in some handler before calling importFile. For variety

    I use the IMPORTFILEINTO CAST command (it doesn't rename the castmember like the FILENAME OF CAST command).

    on importFile arrayIndex
     global fileList,paletteList
      set whichFile=getAt(fileList,arrayIndex)
      importFileInto cast "thePICT", whichFile
    end
    
    or...

    The following is untested--I'd be surprised if this worked since I'm not sure that Director will actually update the palette with puppetPalette before the file is imported. You probably need to set the correct palette in one frame then call importFile in the next frame (the problem is making sure that Director actually SETS the new palette BEFORE you import the file and I recall that this did not occur reliably if you did this in the same handler)

    on importFile arrayIndex
     global fileList,paletteList
      set whichFile=getAt(fileList,arrayIndex)
      set whichPalette=getAt(paletteList,arrayIndex)
      puppetPalette whichPalette
      updateStage
      importFileInto cast "thePICT", whichFile
    end
    
    -Jeff Markham
    UCLA School of Medicine
    Dept. Molecular and Medical Pharmacology
    Crump Institute for Biological Imaging
    10833 LeConte Ave
    Los Angeles, CA 90024-6948
    jmarkham@mail.nuc.ucla.edu
    http://www.nuc.ucla.edu