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
Windows and Cascading Menus for Shockwave
DirectInteraction Xtra.
Sprite Blender - Time
Toggle ImageEnabled Property of a Flash Sprite
Set Quality of a Flash Cast member
Prepare for movie (Sound Card and Screen Saver Check)
Stop MPEG with MCI commands
Random numbers from file names -w/ BuddyAPI
Wait for X seconds, go to marker
bubbleSortForStrings AND bubbleSortForStringLists
 

 

 

Behavior password field

Added on 2/6/2001

 

Compatibilities:
behavior D7 D8 Shockwave

This item has not yet been rated

Author: KimSvedmark (website)

Attach this behaviour to any field object, set the maxlength and allowed character properties and you"re set to go. If you require an event to be triggered when users press return, implement this at the "36:" case in the keyDown handler. To retrieve the actual password, use the "getPassword" handler.

--  lingo password field behaviour  --
--                                  --
--  author: kim svedmark            --
--  created: 2001-02-02             --
--  email: kim.svedmark@framfab.se  --
--------------------------------------

-- script properties
property sPassword  -- the actual input
property sPassMask  -- password mask
property sPassMaxLen  -- password max length
property sAllowChars  -- string of allowed characters
property myMember  -- pointer to the field member

-- beginSprite event handler
on beginSprite me
  
  -- initialize the script properties
  sPassword = empty
  repeat with i = 1 to sPassMaxLen -- create the password mask
    sPassMask = sPassMask & "s"  
  end repeat
  myMember = sprite(me.spritenum).member
  
  -- set up the text field
  if the platform contains "Windows" then
    myMember.font = "WingDings"
  else
    myMember.font = "Wingdings"
  end if
  
  myMember.editable = true
  myMember.wordWrap = false
  myMember.text = empty
  
end

-- keyDown event handler
on keyDown me
  
  if sAllowChars contains the key then  -- the user pressed an allowed character
    
    if the selStart = the selEnd and length(sPassword) = sPassMaxLen then return  
    
    -- remember the character, add a password mask character and move the cursor    
    sPassword = chars(sPassword, 1, the selStart) & the key & chars(sPassword, the selEnd + 1, length(sPassword))
    myMember.text = chars(sPassMask, 1, length(sPassword))
    the selStart = the selStart + 1
    
    -- if an area was selected, we need to move the selection end property
    if not (the selStart = the selEnd) then
      the selEnd = the selStart
    end if
    
  else
    
    case the keycode of  -- the user pressed som other button
        
      51: -- backspace
        if the selStart = the selEnd then
          sPassword = chars(sPassword, 1, the selStart - 1) & chars(sPassword, the selEnd + 1, length(sPassword))
        else
          sPassword = chars(sPassword, 1, the selStart) & chars(sPassword, the selEnd + 1, length(sPassword))
        end if
        pass
        
      117: -- delete
        if the selStart = the selEnd then
          sPassword = chars(sPassword, 1, the selStart) & chars(sPassword, the selEnd + 2, length(sPassword))
        else
          sPassword = chars(sPassword, 1, the selStart) & chars(sPassword, the selEnd + 1, length(sPassword))
        end if
        pass
        
      115,119,123,124: -- handle home/end and left/right arrow buttons normally
        pass
        
      36: -- enter/return, customize this if you want
        return
        
      otherwise -- all other keys, we ignore
        return
        
    end case
    
  end if    
  
end

-- getPassword returns the actual password
on getPassword me
  return sPassword
end

-- getPropertyDescriptionList handler
on getPropertyDescriptionList me
  
  set pdlist to [:]
  
  addProp pdlist, #sPassMaxLen, [#comment:"Password max length:", #format:#integer, #default: 20, #range:[#min:1,#max:99]]
  addProp pdlist, #sAllowChars, [#comment:"Allowed characters:", #format:#string, #default:"abcdefghijklmnopqrstuvwzyxABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890"]
  
  return pdlist  
end

 


Contact

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

Send e-mail