as3 TypeWriter Effect
code source :
import com.mutationevent.TypeWriter; var tw:TypeWriter = new TypeWriter(theText, 1, 10); tw.addEventListener(TypeWriter.COMPLETE, onComplete); function onComplete(event:Event) { trace("complete", event); }
class :
/* * Copyright 2009 Achraf bouyakhsass [http://www.mutationevent.com] * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mutationevent { import flash.events.*; import flash.utils.Timer; import flash.text.TextField; public class TypeWriter extends EventDispatcher { private var timer:Timer; private var count:Number = 0; private var str:String; private var target:TextField; private var charJump:Number = 1; private var speed:Number = 50; public static var COMPLETE:String = "complete"; public function TypeWriter(tf:TextField, cj:Number, sp:Number) { charJump = cj; speed = sp; target = tf; str = target.text; target.text = ""; timer = new Timer(speed); timer.addEventListener(TimerEvent.TIMER, write); timer.start(); } private function write(event:TimerEvent):void { target.text = str.substring(0, count); count += charJump; if(count > str.length) { timer.removeEventListener(TimerEvent.TIMER, write); dispatchEvent(new Event(TypeWriter.COMPLETE)); } } } }
Télécharger le fichier ici : as3 TypeWriter (87)
No related posts.
Tags: as3, typewriter



10 août 2009 à 10:09
cet effet est basé sur l’exemple de Lee Brimelow sur gotoandlearn écrit en actionscript 2.