Payday Loans Online Payday Loans Online

Todd Rothe : UI/UX Developer

it's pronounced rowth-ee

By 2g1c2 girls 1 cup

fromCharCode() With A Side Of charCodeAt() or Grab Previous Letter

While working on an address book application I came across a use of fromCharCode() in combination with charCodeAt(). I’m not sure how else you would execute the following use case but this is one great use of fromCharCode() and charCodeAt() and totally worth sharing. Thanks Peter Chanthamynavong (AS3/Flex guru).

Use Case: In an address book type application with letters A to Z running vertically down the right side, when a user clicks R and there are on contacts under R then the application should display the entries under Q. If there are no entries under Q then the address book should display the entries under P, and so on.

I’ve placed some code below for a sample app that takes the letter entered into the text field and gives you the letter before it when you click the button. For the use case above you would automate the evaluation of the letter and set the vertical scroll position of the list to the ArrayCollection.getItemIndex(person) when the person.lastName.charAt(0) == letter.




private function onCreationComplete():void
{
submit.addEventListener(MouseEvent.CLICK, showPreviousLetter);
}
private function showPreviousLetter(event:Event):void
{
var newLetter:String;

if( letter.text.toLowerCase() != "a" )
{
newLetter = String.fromCharCode( Number(letter.text.toLowerCase().charCodeAt(0))-1);
}
else
{
newLetter = "Z"
}

letter.text = newLetter;
}
]]>



more posts at www.toddrothe.com/blog

 

No Responses to “fromCharCode() With A Side Of charCodeAt() or Grab Previous Letter” (post new)

 

Leave a Reply

You must be logged in to post a comment.