2014-09-21 55 views
-1

进出口新的ActionScript 3中,我试图得到一个数字来耗尽时,我都会启动一个定时器AS3动态文本

到目前为止,香港专业教育学院得到它,所以你按一下按钮“btngo”和一个计时器开始,而球对象移动。

我也想开始于100动态文本单击此按钮时向下消耗到0在10秒内,但不幸的是我不知道该怎么办呢

任何帮助将不胜感激,谢谢你:)

import flash.utils.Timer; 
import flash.events.TimerEvent; 

stop(); 


var timer1:Timer = new Timer (10,10000); 
var timer2:Timer = new Timer (10,10000); 
timer1.addEventListener(TimerEvent.TIMER, forward); 
timer2.addEventListener(TimerEvent.TIMER, back); 
btngo.addEventListener(MouseEvent.CLICK, green); 
btnstop.addEventListener(MouseEvent.CLICK, red); 

function green(e:MouseEvent):void { 
    timer2.stop(); 
    timer1.start(); 
    trace("timer started"); 
} 

function red(e:MouseEvent):void { 
    timer1.stop(); 
    timer2.start(); 
    trace("timer started"); 
} 

function forward(e:TimerEvent):void { 
    ball.x += 2; 
} 

function back(e:TimerEvent):void { 
    ball.x -= 2; 
} 

回答

0

那么,这里有两个函数,它们会帮助你找到你想要的东西。这第一个是文本的创作:

import flash.text.TextField; 
import flash.text.TextFieldType; 

var dynamic_text:TextField; 
function CreateText() 
{ 
    // You can also replace this part with code that creates a textfield that you have in your library, 
    // in that case just make sure the textfield is set to dynamic in the textfield properties 

    // Create a new textfield. 
    dynamic_text = new TextField(); 

    // Make sure its type is set to Dynamic. 
    dynamic_text.type = TextFieldType.DYNAMIC; 

    // Position it somewhere on the screen. 
    dynamic_text.x = 10; 
    dynamic_text.y = 10; 

    // Set a default text for now. 
    dynamic_text.text = "Time: " + time_left; 

    // Make sure the players cannot select the text. 
    dynamic_text.selectable = false; 

    // Add it to your stage (or other parent, take your pick) 
    stage.addChild(dynamic_text); 
} 

这第二个被称为每TimerEvent:

function OnTimerChange() 
{ 
    // Update the text based on the new time. 
    dynamic_text.text = "Time: " + time_left; 
} 

你将不得不调用里面你自己的“前进”和“后退”这OnTimerChange功能函数,在这两个函数中,你将不得不计算已经过了多少时间。

举一个例子如何保持的,因为你按下按钮所经过的时间轨迹: actionscript 3 how to keep track of time elapsed?

希望这有助于。