我正在使用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);
}
答案 0 :(得分:0)
答案 1 :(得分:0)
我认为这会给你一个错误,但你总是可以尝试
timerText.text = String(minutes) + ":" + String(seconds);
将数字转换为字符串并允许它们显示在文本字段中。