Actionscript 3 AS3中未更新动态文本框
我正在使用ActionScript3开发一个Flash MP3播放器。我在舞台上的播放、暂停等按钮旁边有一个动态文本框,实例名为“timerText” 使用当前分钟和秒更新timerText字段的代码是从一个名为onEnterFrame的函数调用的,该函数附加到EnterFrame事件侦听器 我已经在动态文本框中嵌入了字体,当我调用trace函数从动态文本框中打印出当前文本时,它会打印出它应该打印的时间。然而,文本框本身根本不会改变 在我的时间线中有一个框架,附带以下操作:Actionscript 3 AS3中未更新动态文本框,actionscript-3,flash,actionscript,flash-cs5,Actionscript 3,Flash,Actionscript,Flash Cs5,我正在使用ActionScript3开发一个Flash MP3播放器。我在舞台上的播放、暂停等按钮旁边有一个动态文本框,实例名为“timerText” 使用当前分钟和秒更新timerText字段的代码是从一个名为onEnterFrame的函数调用的,该函数附加到EnterFrame事件侦听器 我已经在动态文本框中嵌入了字体,当我调用trace函数从动态文本框中打印出当前文本时,它会打印出它应该打印的时间。然而,文本框本身根本不会改变 在我的时间线中有一个框架,附带以下操作: import fla
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);
}
导入flash.media.Sound;
导入flash.media.SoundChannel;
导入flash.media.SoundLoaderContext;
导入flash.events.MouseEvent;
导入flash.net.URLRequest;
导入flash.events.Event;
//阻止球员
停止();
/**
*声明一些变量
*/
//获取MP3文件
var-req:URLRequest=newurlrequest('audio/alice-track-1.mp3');
//创建一个声音对象
var snd:Sound=新声音();
//创建一个声音通道
var通道:声音通道;
//初始化暂停位置
var pausePosition:int=0;
//正在播放的布尔值(?)
var isPlaying:Boolean=false;
//将播放缓冲区设置为5秒
变量上下文:SoundLoaderContext=新的SoundLoaderContext(5000,true);
//将请求的URL与上下文一起加载到Snd变量中
snd.load(请求、上下文);
//创建播放频道
频道=snd.play();
//最初将IsPlaying设置为TRUE
isplay=true;
/**
*播放音乐功能
*/
函数播放声音(事件:MouseEvent):无效{
如果(显示==假){
频道=单音播放(暂停位置);
isplay=true;
}
}
/**
*停止音乐功能
*/
功能停止声音(事件:MouseEvent):无效{
channel.stop();
pausePosition=0;
isplay=false;
}
/**
*暂停音乐功能
*/
函数pauseSound(事件:MouseEvent):void{
pausePosition=通道位置;
channel.stop();
isplay=false;
}
//添加按钮事件侦听器
playBtn.addEventListener(MouseEvent.CLICK,播放声音);
stopBtn.addEventListener(MouseEvent.CLICK,stopSound);
pauseBtn.addEventListener(MouseEvent.CLICK,pauseSound);
//添加OnEnterFrame事件侦听器
addEventListener(Event.ENTER_FRAME,onEnterFrame);
/**
*初始化/单帧功能
*/
函数onEnterFrame(事件:事件):void{
var totalSeconds:Number=channel.position/1000;
变量分钟数:数字=数学地板(总秒数/60);
var秒数=数学地板(总秒数)%60;
如果(秒<10){
秒='0'+秒;
}
timerText.text=(分钟+':'+秒);
跟踪(timerText.text);
}
这可能是字体嵌入问题
请确保已启用字体嵌入选项中的“全部”按钮。
看看他的形象-
另外,请确保字体颜色与背景颜色不同。通过查看,我发现“分钟”和“秒”是数字,而不是字符串 我以为这会给你一个错误,但你可以一直尝试
timerText.text = String(minutes) + ":" + String(seconds);
这将数字转换为字符串,并允许它们显示在文本字段中。您不需要让它每帧运行一次,因为您只显示分钟和秒,而是将计时器设置为900毫秒。另外,你需要一个文本框或文本字段吗?我在舞台上有一个动态文本框,实例名为“timerText”。听起来好像字体没有正确嵌入。如果不嵌入字体,它能工作吗?@Gone3d这是一个离题,但这不是很优雅,因为时间显示有时会显示几乎2秒的相同时间,其余时间为900毫秒。900毫秒是.9秒-它确保您在不到一秒的时间内用一点缓冲进行更新。如果在900毫秒时发现问题,请将其降低到0.5秒或500毫秒。如果你是30fps,那就是33ms,差别很大。我仔细检查了一下,字体肯定是嵌入的(我选择了“全部”字符)。字体设置为白色,背景为黑色,因此应该可见。正如我所说,当我跟踪timerText.text时,它会打印正确的值。文本框似乎没有任何输出。