'Flash'에 해당되는 글 1건

  1. 2009/03/24 매트릭스(?) 문자효과 흉내내기. (1)
2009/03/24 13:17
정확한 명칭은 뭔지 잘 몰르겠네요.
이런저런 사이트에서 많이 쓰는 효과인데 연습삼아 한번 만들어봤습니다.
사용된 메소드가 3개뿐이고 그중 2개는 랜덤문자를 형성하기 위한것이라 소스상에는 어려울것이 없어보입니다.
그럼 많은 참고가 되길바랍니다~~



  1. var testString:String = "http://www.heyon.com Have yourself to cookie. bravo my life~~ ah hat hat";
  2. var tmpText:String = "";
  3.  
  4. // 초기값 세팅
    testText.text = SetRandChar(testString.length);
  5. testText.addEventListener(Event.ENTER_FRAME, ShowMatrix);
  6.  
  7. /**
  8. * 매트릭스 실행
  9. * @param e : enter frame event
  10. */
  11. var i:Number = 0;
  12. function ShowMatrix(e:Event):void {
  13.         // 텍스트 길이 만큼만 실행
  14.         if (i <= testString.length) {
  15.                 // tmpText 변수에 testString을 한글자씩 늘리고 랜덤문자는 한글자씩 줄인걸 합하여 대입한다.
  16.                 tmpText = testString.substr(0, i) + SetRandChar(testString.length - i);
  17.                 testText.text = tmpText;
  18.         } else {
  19.                 // 텍스트 길이를 넘어가면 index를 초기화 하고 enter frame을 종료한다.
                    i = 0;
  20.                 testText.removeEventListener(Event.ENTER_FRAME, ShowMatrix);
  21.         }
  22.         i++;
  23. }
  24.  
  25. /**
  26. * 랜덤 문자 채우기
  27. * @param textCnt : 텍스트길이
  28. * @param beginCharCode : char code 랜덤 범위 시작점
  29. * @param endCharCode : char code 랜덤 범위 끝점
  30. * @return returnText : 랜덤문자열
  31. */
  32. function SetRandChar(textCnt:Number = 0, beginCharCode:Number = 80, endCharCode:Number = 120):String {
  33.         var returnText:String = "";
  34.        
  35.         for (var i:Number = 0; i < textCnt; i++) {
  36.                 returnText = returnText + String.fromCharCode(randRange(beginCharCode, endCharCode));
  37.         }
  38.        
  39.         return returnText;
  40. }
  41.  
  42. /**
  43. * 랜덤 범위
  44. * @param beginCharCode : 최소값
  45. * @param endCharCode : 최대값
  46. */
  47. function randRange(beginCharCode:Number, endCharCode:Number):Number {
  48.         var randomNum:Number = Math.floor(Math.random() * (endCharCode - beginCharCode + 1)) + beginCharCode;
  49.         return randomNum;
  50. }
 FLA다운로드
matrix.fla
크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by James On