我正在创建简单的音乐播放器。它只会播放一首歌曲。我想创建一个非常简单的搜索栏。我希望一个图形用作搜索组件 - 因此它可以左右移动(在 x 轴上的两个点之间:图形当前所在的起点和歌曲结束时的终点)并对应于歌曲的channel.position。所以总结一下:我想请一个善良的灵魂给我一个提示,我应该使用什么代码来使图形在 x 轴上以对应于歌曲的 channel.position 的方式移动。
到目前为止,这是我的代码:
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;
}
}
忽略movieClip_1,因为它只是在播放音乐时运行的动画。