动态文本框未在AS3中更新

时间:2013-02-07 15:43:31

标签: actionscript-3 flash actionscript flash-cs5

我正在使用Actionscript 3制作Flash MP3播放器。我在播放,暂停等按钮旁边的舞台上有一个实例名称为“timerText”的动态文本框。

使用名为onEnterFrame的函数调用使用当前分钟和秒更新timerText字段的代码,该函数附加到EnterFrame事件侦听器。

我已将字体嵌入到动态文本框中,当我调用trace函数从Dynamic文本框中打印出当前文本时,它会打印出应该的时间。但是,文本框本身并没有改变。

我的时间轴中有1个框架,附加了以下操作:

import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundLoaderContext;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.events.Event;

// Stop the Player
stop();

/**
* Declare some Variables
*/

// Get the MP3 File
var req:URLRequest = new URLRequest('audio/alice-track-1.mp3');

// Create a Sound Object
var snd:Sound = new Sound();

// Create a Sound Channel
var channel:SoundChannel;

// Initialise the Pause Position
var pausePosition:int = 0;

// Boolean for Is Playing(?)
var isPlaying:Boolean = false;

// Set the Play Buffer to 5 Seconds
var context:SoundLoaderContext = new SoundLoaderContext(5000, true);

// Load the Requested URL into the Snd Var, along with the Context
snd.load(req, context);

// Create the Play Channel
channel = snd.play();

// Set IsPlaying to TRUE initially
isPlaying = true;

/**
* Play Music Function
*/
function playSound(event:MouseEvent):void {
    if (isPlaying == false) {
        channel = snd.play(pausePosition);
        isPlaying = true;
    }
}

/**
* Stop Music Function
*/
function stopSound(event:MouseEvent):void {
    channel.stop();
    pausePosition = 0;
    isPlaying = false;
}

/**
* Pause Music Function
*/
function pauseSound(event:MouseEvent):void {
    pausePosition = channel.position;
    channel.stop();
    isPlaying = false;
}

// Add the Button Event Listeners
playBtn.addEventListener(MouseEvent.CLICK, playSound);
stopBtn.addEventListener(MouseEvent.CLICK, stopSound);
pauseBtn.addEventListener(MouseEvent.CLICK, pauseSound);

// Add the OnEnterFrame Event Listener
addEventListener(Event.ENTER_FRAME, onEnterFrame);

/**
* Initialisation / OnEnterFrame Function
*/
function onEnterFrame(event:Event):void {
    var totalSeconds:Number = channel.position / 1000;
    var minutes:Number = Math.floor(totalSeconds / 60);
    var seconds = Math.floor(totalSeconds) % 60;

    if (seconds < 10) {
        seconds = '0' + seconds;
    }

    timerText.text = (minutes + ':' + seconds);
trace(timerText.text);
}

2 个答案:

答案 0 :(得分:0)

这可能是字体嵌入问题。

请确保您已启用font-embed选项中的all按钮。 看看这张图片 - http://i.imgur.com/F5ufM.png

另外,请确保字体颜色与背景颜色不同。

答案 1 :(得分:0)

通过观察这个,我看到“分钟”和“秒”是数字,而不是字符串。

我认为这会给你一个错误,但你总是可以尝试

timerText.text = String(minutes) + ":" + String(seconds);

将数字转换为字符串并允许它们显示在文本字段中。

相关问题