www.mutationevent.com

as3 TypeWriter Effect

code source :

  1. import com.mutationevent.TypeWriter;
  2. var tw:TypeWriter = new TypeWriter(theText, 1, 10);
  3. tw.addEventListener(TypeWriter.COMPLETE, onComplete);
  4. function onComplete(event:Event)
  5. {
  6. trace("complete", event);
  7. }

class :

  1. /*
  2. * Copyright 2009 Achraf bouyakhsass [http://www.mutationevent.com]
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.mutationevent
  17. {
  18. import flash.events.*;
  19. import flash.utils.Timer;
  20. import flash.text.TextField;
  21.  
  22. public class TypeWriter extends EventDispatcher
  23. {
  24. private var timer:Timer;
  25. private var count:Number = 0;
  26. private var str:String;
  27. private var target:TextField;
  28. private var charJump:Number = 1;
  29. private var speed:Number = 50;
  30. public static var COMPLETE:String = "complete";
  31.  
  32. public function TypeWriter(tf:TextField, cj:Number, sp:Number)
  33. {
  34. charJump = cj;
  35. speed = sp;
  36. target = tf;
  37. str = target.text;
  38. target.text = "";
  39.  
  40. timer = new Timer(speed);
  41. timer.addEventListener(TimerEvent.TIMER, write);
  42. timer.start();
  43. }
  44. private function write(event:TimerEvent):void
  45. {
  46. target.text = str.substring(0, count);
  47. count += charJump;
  48. if(count > str.length)
  49. {
  50. timer.removeEventListener(TimerEvent.TIMER, write);
  51. dispatchEvent(new Event(TypeWriter.COMPLETE));
  52. }
  53. }
  54. }
  55. }

Télécharger le fichier ici : as3 TypeWriter (87)

No related posts.

Tags: ,

Un commentaire pour “as3 TypeWriter Effect”

  1. admin dit :

    cet effet est basé sur l’exemple de Lee Brimelow sur gotoandlearn écrit en actionscript 2.

Laisser un commentaire

*
Pour prouver que vous n'êtes pas un bot, recopiez le code ci-dessous
Anti-Spam Image



  • Archives

  • Catégories

  • @mutationevent