Animated GIF

From Director Online Wiki
Jump to: navigation, search

Description

A quick and easy way of showing simple bitmap animations in Director are animated gifs. I just never knew -with dynamically imported gifs- whether they were animated or just static gif images, and since I didn't find out any better way to do that, I wrote the following handler in two flavours. it requires fileIO .. and a gif.

Usage

For the general usage of animated gif members meanwhile please check the docs here: http://livedocs.macromedia.com/director/mx2004/release_en/03_medi2.htm

Acai Berry is the best supplement available in the market. Acai Berry has been a revolution and is preferred by most of the people. There are various benefits of [1] but they are questioned at times. Acai Berry is quite helpful for the weight losers and this fruit also provides you with enormous amount of energy.


Properties

fileName

string fullPath

get/set

Incorrectly documented as .path property, which does not exist for animated gifs. However .fileName does, but caution: when you just set the fileName of an animated gif member, it will change its memberType to #bitmap and thus lose its animation features. See here how to prevent this.

fixedRate

integer fps

get/set

Incorrectly documented as .frameRate property. Attempts to get or set the .frameRate will produce a script error. Referring to .fixedRate however works fine. But caution: You might not see any result in playback behaviour, that's probably due to a .playBackMode property set other than to #fixed.

playBackMode

symbol #normal|#lockStep|#fixed

get/set

when set to #normal, the gif plays with its original framerate if possible. when set to #lockStep, the gif plays with the movie's framerate if possible. when set to #fixed, and only then, the gif plays with the defined .fixedRate.

media

The .media property exists for animated gif members, but it seems to always return 0, and attempts to set its value (e.g. to the media of a second animGif member) produces a script error.

If anyone knows about ways to manipulate the animGif media, e.g. inserting frames etc. any updates on this page are very welcome!



no?جº?íit dong't always return 0

import:

1.include original data for editing :put member(2).media

                                    -- (media 3b36618)

2.standard import : put member(3).media

                                    -- 0

Methods

resume()

pause()

rewind()

Lingo: How to...

Import an animGif with lingo

It is possible to import a new #animGif member with lingo, but you do need to trick around a little:

vMem =          new( #animgif )
vMem.linked =   TRUE  -- prevents vMem from changing its type to #bitmap
vMem.filename = "c:\anitest.gif"
vMem.linked =   FALSE -- optional. this will unlink the member from the file.

Know if it's really animated

on GifIsAnimated(aFilePath) ------------------------------------------
  -- INPUT: <aFilePath> should be a string path to a GIF file
  -- OUTPUT: Returns 1 if the given file is an animated GIF, 0 if the
  --         file is readable but is not an animated GIF, or a 
  --         negative integer if an error occurs
  -- XTRAS:  Assumes that the FileIO xtra is available
  -- AUTHOR: ben@benjaminalbrecht.com
  -- SAMPLE: put gifIsAnimated( "c:\myGif.gif" )
  --         -- 1
  --------------------------------------------------------------------
 
  vOutput = FALSE
 
  vFileIO = xtra("fileio").new()
 
  vFileIO.openFile(aFilePath, 1)
  vError = vFileIO.status()
  if vError then
    -- The file could not be opened
    vOutput = vError
   
  else
    -- All animated GIFs start with the string "GIF89a" or "GIF89b"
    vVersion = vFileIO.readWord().char[1..6]
    if ["GIF89a", "GIF89b"].getPos(vVersion) then
     
      -- All animated GIFs contain the string "NETSCAPE2.0"
      vLength = vFileIO.getLength()
     
      repeat while vFileIO.getPosition() < vLength
        if vFileIO.readWord() contains "NETSCAPE2.0" then 
          vOutput = TRUE
          exit repeat
        end if
      end repeat
    end if
   
    vFileIO.closeFile()
  end if
 
  return vOutput  
end GifIsAnimated


on GifGetFileInfo(aFilePath) -----------------------------------------
  -- INPUT: <aFilePath> should be a string path to a GIF file
  -- OUTPUT: Returns an error code or a property list like:
  --         [#GIF:      <Boolean>,
  --          #animated: <Boolean>,
  --          #version:  <#gif89a | #gif87a | #gif89b | VOID>]
  -- XTRAS:  Assumes that the FileIO xtra is available
  -- AUTHOR: ben@benjaminalbrecht.com
  -- SAMPLE: put GifGetFileInfo( "c:\myGif.gif" )
  --         -- [#GIF: 1, #animated: 1, #version: #gif89a]
  --------------------------------------------------------------------
 
  vOutput = [#GIF: FALSE, #animated: FALSE, #version: VOID]
 
  vFileIO = xtra("fileIo").new()
 
  vFileIO.openFile(aFilePath, 1)
  vError = vFileIO.status()
  if vError then
    -- The file could not be opened
    vOutput = vError
   
  else  -- All GIFs start with the string "GIF8.."
    vVersion = vFileIO.readWord().char[1..6]
    case vVersion of
      "GIF89a", "GIF87a", "GIF89b":
        vOutput.GIF     = TRUE
        vOutput.version = symbol(vVersion)
       
        if vVersion starts "GIF89" then
          -- GIFs which start "GIF89" and contain the string
          -- "NETSCAPE2.0" are animated
          vLength = vFileIO.getLength()
          repeat while vFileIO.getPosition() < vLength
            if vFileIO.readWord() contains "NETSCAPE2.0" then 
              vOutput.animated = TRUE
              exit repeat
            end if
          end repeat
        end if
    end case
   
    vFileIO.closeFile()
  end if
 
  return vOutput
end GifGetFileInfo