我正在创建一个只播放一首歌曲的简单音乐播放器。阶段时间线只有一帧。播放器的主要图形是movieClip_1(它在自己的时间线上有4帧)并且工作正常。我有按钮(button_2),它可以启动和暂停歌曲和movieClip_1(工作正常)。而且我还有一个图形(它被称为管 - 我已将其更改为电影剪辑,它在时间轴内有一个帧)作为搜索栏组件,我只是希望它相应地移动到这首歌在频道上的位置x 轴,但它给了我三重错误:
TypeError:错误 #1009:无法访问空对象引用的属性或方法。此行的调试点:
tube.x = (chan.position/song.length) * 83;
我非常感谢有关错误的提示以及使用什么方法,以便用户能够通过在 x 轴上移动管并转到歌曲的不同部分来导航(用鼠标)通过歌曲。我读到了 .startDrag 和 .stopDrag 对我现在的代码来说是个好主意吗?
到目前为止我的代码:
movieClip_1.stop();
var itsstoped:Boolean;
var youpausedit:Boolean;
var counter:Timer = new Timer(100);
var chan:SoundChannel;
var song:Sound = new Sound();
song.load(new URLRequest("wmc2.mp3"));
song.addEventListener(Event.COMPLETE, soundloaded);
function soundloaded(event:Event)
{
trace("Song has been loaded.");
}
counter.addEventListener(TimerEvent.TIMER,countcounter);
itsstoped = true;
youpausedit = false;
button_2.addEventListener(MouseEvent.CLICK, presser);
function presser(event:MouseEvent):void
{
if(itsstoped == true && youpausedit == true)
{
movieClip_1.gotoAndPlay(1);
chan = song.play(chan.position);
itsstoped = false;
}
else if(itsstoped == false)
{
movieClip_1.gotoAndStop(1);
chan.stop();
itsstoped = true;
youpausedit = true;
}
else if(itsstoped == true && youpausedit == false)
{
movieClip_1.gotoAndPlay(1);
chan = song.play();
counter.start();
itsstoped = false;
}
}
function countcounter(e:TimerEvent):void
{
trace(chan.position/song.length);
var percentage:uint = 100 * (chan.position / song.length);
trace(percentage);
if(percentage == 100)
{
movieClip_1.gotoAndStop(1);
itsstoped = true;
youpausedit = false;
counter.stop();
}
}
tube.buttonMode = true;
tube.useHandCursor = true;
addEventListener(Event.ENTER_FRAME, movewhenplay);
function movewhenplay(e:Event):void
{
tube.x = (chan.position/song.length) * 83;
}