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
HJ Install
Video Mask
Macromedia Director Game Development: From Concept to Creation
aougu.com
Increase/ Decrease FrameRate of a Flash Member
Icon Forge
Force Characters
Internet Explorer 5 - PC
Volume Control Dial
Runtime Debugging Utilities
 

 

 

Behavior Palindrome Check

Added on 5/21/2001

 

Compatibilities:
behavior D7 D8 D8_5 Mac PC Shockwave

This item has not yet been rated

Author: KurtKoenig (website)

Checks a word to see if its a palindrome

Download PC Source    Download Mac Source
---------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
--   PALINDROME CHECK
--
--   Use a repeat loop to check if the characters (or numbers) in the first half of a
--   field are equal to the characters in the last half, starting from the last one.
--
--   Kurt * Belgium     05/14/2001
--
---------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
on mouseup me
  
  --First this behavior counts how many characters there are in your word,
  --and puts this number in a variabele.
  Characters = (member "Word").chars.count
  
  --The number of characters is divided in two (integer division), so the repeat
  --loop can compare the characters in the first half with the characters in the last half
  Firsthalf = Characters / 2
  
  --The value in Palindrome is used later, when its equal to the value in Firsthalf;
  --the word is a palindrome.
  Palindrome = 0
  
  repeat with I = 1 to Firsthalf
    --If the first character = the last character Palindrome's value gets increased
    if (member "Word").char[I] = (member "Word").char[Characters] then
      Palindrome = Palindrome + 1
    end if
    
    --The last character becomes the last but one ("I" will represent the second
    --character in the next loop)
    Characters = Characters - 1
  end repeat
  
  --If the two values match, it's a palindrome,it doesn't matter if the word has
  --an odd number of characters, the one in the middle isn't compared to anything.
  if Palindrome = Firsthalf then
    alert "This is a palindrome !"
  else
    alert "This is not a palindrome !"
  end if
  
end mouseup

 


Contact

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

Send e-mail