As3 Initial Caps


/ Published in: ActionScript 3
Save to your folder(s)

function to replace any capital letters with Large letters and make everything capitalized


Copy this code and paste it in your HTML
  1. public static function initialize(t:TextField, normSize:int = 12, largeSize:int = 17, auto_size:Boolean = true):void {
  2. var upArray:Array = new Array();
  3. var firstCharFormat:TextFormat = new TextFormat();
  4. firstCharFormat.size = largeSize;
  5. var normalFormat:TextFormat = new TextFormat();
  6. normalFormat.size = normSize;
  7. if(auto_size){
  8. t.autoSize = TextFieldAutoSize.LEFT;
  9. }
  10. var str:String = t.text;
  11. var length:Number = t.text.length;
  12. for (var j:int = 0; j < length; j++) {
  13. if (str.charCodeAt(j) > 64 && str.charCodeAt(j) < 91) {
  14. upArray.push(true);
  15. }else {
  16. upArray.push(false);
  17. }
  18. }
  19. t.text = t.text.toUpperCase();
  20. for (var i:int=0; i < length; i++)
  21. {
  22. if (upArray[i] || str.charAt(i) == " ") {
  23. t.setTextFormat(firstCharFormat, i);
  24. }else {
  25. t.setTextFormat(normalFormat, i);
  26. }
  27. }
  28. }

Report this snippet


Comments


You need to login to view comments.