AS3 文字特效

package com.mtm.effect {

import com.greensock.TweenMax;
import com.mtm.shape.Border;

import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.display.Sprite;
import flash.display.StageScaleMode;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.filters.GlowFilter;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFormat;
import flash.utils.Timer;

/**
* @author mapeijie
*/
public class CharacterFlyOut {


private var AllChars:String = "TextField类用于创建显示对象以显示和输入文本." 
+ "这与Web浏览器的文本在HTML文档中嵌入的媒体旁换行非常类似," 
+ "FlashPlayer还支持部分 HTML标签,可以使用这些HTML标签设置文本格式." 
+ "要查看受支持HTML标签的列表,请参阅对htmlText属性的描述.";

private var countTotal:uint;
private var txtInfo:TextField;
private var bridgeStr:String = "";
private var txtFormate:TextFormat;

private var sprite:Sprite;

public function CharacterFlyOut(_sprite:Sprite) {

this.sprite = _sprite;

sprite.stage.color = 0xf0f0f0;
sprite.stage.scaleMode = StageScaleMode.SHOW_ALL;
sprite.addChild(new Border(sprite.stage.stageWidth, sprite.stage.stageHeight, 30, 0x000000));

bridgeStr = txtInfo.text;
countTotal = txtInfo.length;

txtFormate = new TextFormat();
txtFormate.font = "Verdana";
txtFormate.color = 0xFF3300;

initTxtArea();

initPlayBtn();
}


private function initTxtArea():void {
txtInfo = new TextField();
txtInfo.x = 10;
txtInfo.y = 10;
txtInfo.width = 300;
txtInfo.height = 220;
txtInfo.wordWrap = true;
txtInfo.multiline = true;
txtInfo.background = true;
txtInfo.htmlText = AllChars;
txtInfo.textColor = 0xff00ff;
txtInfo.backgroundColor = 0xffff00;
txtInfo.type = TextFieldType.INPUT;
sprite.addChild(txtInfo);
}

private function initPlayBtn():void {
var label:TextField = new TextField();
label.x = 400;
label.y = 300;
label.text = "开始演示";
label.multiline = false;
label.background = true;
label.mouseEnabled = true;
label.backgroundColor = 0xff00ff;
label.width = label.textWidth + 3;
label.height = label.textHeight + 3;
label.addEventListener(MouseEvent.CLICK, onBtnClick);
sprite.addChild(label);
}

private function initTimer():void {
var tAnim:Timer = new Timer(100, countTotal);
tAnim.addEventListener(TimerEvent.TIMER, textStartFly);
tAnim.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
tAnim.start();
}


private function textStartFly(_evt:TimerEvent):void {
var oneCharTF:TextField = new TextField();
txtFormate.size = Math.random() * 48 + 12;
oneCharTF.defaultTextFormat = txtFormate;
oneCharTF.text = bridgeStr.charAt(0);
oneCharTF.selectable = false;

//动态设置剩余字符
bridgeStr = bridgeStr.substr(1);
txtInfo.text = bridgeStr;

sprite.addChild(oneCharTF);


TweenMax.to(oneCharTF, 2, {x: -100, y: sprite.stage.stageHeight - 50, bezier: [{x: 500, y: 0}, {x: 500, y: 300}], onComplete: clearText, onCompleteParams: [oneCharTF]});
}

/**
* 完成飞--复原文字
* @param _evt
*/
private function onTimerComplete(evt:TimerEvent):void {
txtInfo.htmlText = AllChars;
txtInfo.width = txtInfo.textWidth + 5;
txtInfo.height = txtInfo.textHeight + 5;
bridgeStr = txtInfo.text;
}

/**
* 鼠标点击开始
* @param _evt
*/
private function onBtnClick(evt:MouseEvent):void {
initTimer();
}

/**
* 飞出界面的TF清楚掉
* @param _mc
*/
private function clearText(displayObj:*):void {
sprite.removeChild(displayObj);
}

}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值