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 Flash to finish
Director Publications
MM-XDK-L (Developers of Xtras)
Slow Searches - Valentina
Drag around-Alphamania
Drop Files setup
Mastering Macromedia Director 6
Installer Vise
simMode4.0 For multi-moniter
W3D Texture Extractor
 

 

 

Article Command Line Arguments, 3 State Buttons, and Limited Fields

Added on 12/20/1999

 

Compatibilities:
D7 D8 Mac PC Shockwave

This item has not yet been rated

Author: MediaMacros (website)

This week instead of a long article, here are three short behaviors that I get a lot of requests for. Too small for a full article, but useful none the less.

First lets look at the command line question.  I have had numerous
people ask if they could drop a "save" file on the projector's icon (like you
can with word or excel) and have that file load up.  Well, there is an undocumented
feature in Director 7 (yes, another one) that will allow us to read the name of the file
or any arguments that are passed to the projector when it starts up.  This example
reads a text "save" file but it can be modified to respond to various
"switches" or messages on startup.  Remember that this is a windows only
structure, but a nice feature none the less.




  
    
  
--Copyright 1999 Chuck Neal
    --chuck@mediamacros.com
    --If you find this code helpful, send me an e-mail and let me know. :-)
    
    on checkString me
      acceptedTypes = ["txt", "doc"]
      theFile = the commandLine
      theChars = theFile.char.count
      if theFile <> "" and acceptedTypes.getOne(theFile.char[(theChars -
    2)..theChars]) <> 0 then
        --is a valid file dropped or clicked
        myFile = new(xtra "fileIO")
        openFile(myFile, theFile, 1)   
        theText = readFile(myFile)
        closeFile(myFile)
        return theText
      end if
    end
    
    on getBehaviorDescription me
      return "Call this handler to return the text of a file that started your
    projector. Change the acceptedTypes list to the extensions you want to use. For more
    advanced use you can use the file association script in the commercial Buddy API library
    to allow saved files to be double clicked and start automatically."
    end


The second common script I get a lot of requests for is a simple 3 state
button.  Below is a script that allows for a simple button with rollover and click
states.  Just add this to your button, pick the graphics, and go!



 




  
    
  
--Copyright 1999 Chuck Neal
    --chuck@mediamacros.com
    --If you find this code helpful, send me an e-mail and let me know. :-)
    
    property spriteNum, defaultState, clickState, overState, whatDo
    
    on getPropertyDescriptionList me
      p_list = [:]
      curMember = sprite(the currentSpriteNum).member
      p_list.addProp(#defaultState, [#format : #member, #comment : "Default
    image:", #default : curMember])
      p_list.addProp(#overState, [#format : #member, #comment : "Rollover
    image:", #default : member(curMember.number + 1)])
      p_list.addProp(#clickState, [#format : #member, #comment : "Click
    image:", #default : member(curMember.number + 2)])
      p_list.addProp(#whatDo, [#format : #string, #comment : "What to do when
    clicked:", #default : "go next"])
      return p_list
    end
    
    on mouseEnter me
      sprite(spriteNum).member = overState
      updateStage
    end
    
    on mouseLeave me
      sprite(spriteNum).member = defaultState
      updateStage
    end
    
    on mouseDown me
      sprite(spriteNum).member = clickState
      updateStage
    end
    
    on mouseUp me
      sprite(spriteNum).member = overState
      updateStage
      do whatDo
    end
    
    on mouseUpOutside me
      sprite(spriteNum).member = defaultState
      updateStage
    end
    
    on getBehaviorDescription me
      return "This is a standard 3 state button. Drop it on your sprites and select
    the code to run on the mouseUp."
    end


The last of this weeks 3 little scripts is a behavior that will limit a
users input in a field by number of letters and what characters are allowed.  By
dropping this on an editable field it can filter its input to only allow the characters
you want in.




  
    
  
property spriteNum, maxText, allowedKeys, myWrap, otherHandler
    
    on getPropertyDescriptionList me
      p_list = [:]
      p_list.addProp(#maxText, [#format : #integer, #comment : "Max number of
    allowed Characters:", #default : 20])
      p_list.addProp(#allowedKeys, [#format : #string, #comment : "Keys to pass to
    field (Leave blank for all):", #default :
    "1234567890abcdefghijklmnopqrstuvwxyz"])
      p_list.addProp(#myWrap, [#format : #boolean, #comment : "Allow word
    wrapping?", #default : 0])
      return p_list
    end
    
    on beginSprite me
      sprite(spriteNum).wordwrap = myWrap
    end
    
    on keyDown me
      if allowedKeys contains the key and allowedKeys <> "" then
        if sprite(spriteNum).text.char.count > maxText then
          dontpassevent
        else
          pass
        end if
      else if allowedKeys = "" then
        pass
      else
        dontpassevent
      end if
    end
    
    on getBehaviorDescription me
      describe = "This is a simple behavior for text and field members that does the
    following..." & return
      describe = describe & "Limit a field to certain Characters" &
    return & "Limit a field to a certain NUMBER of characters" & "Turn
    the word wrap on/off for the field"
    end


Happy holidays, and happy coding.



As usual, you can also find all of these behaviors/scripts in the behavior database.

 


Contact

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

Send e-mail