我正在尝试构建一个流式.mp3播放器,以便在我的网站上运行各种声音文件。为此,我遵循了一个包含代码模板的教程:
但是,无论是将模板的方向保留在作者自己的声音文件中,还是将自己的方向插入到我的在线声音文件中,我都会在ActionScript中遇到无法理解的故障。
这些错误是:
1084:语法错误:在_之前期待rightparen。
1086:语法错误:在rightparen之前期待分号。
当我尝试纠正它们时,我会遇到新的错误。我无法确定声音文件是否正在加载;它当然永远不会播放。音量滑块不起作用。
我确实找到了一行看起来应该被注释掉的行,即
从同一个地方开始
所以我试着评论出来。没有骰子。同样的错误。
提前感谢任何建议。代码如下:
var musicPiece:Sound = new Sound(new URLRequest _
("http://blog.0tutor.com/JeffWofford_Trouble.mp3"));
var mySoundChannel:SoundChannel;
var isPlaying:Boolean = false;
to start at the same place
var pos:Number = 0;
play_btn.addEventListener(MouseEvent.CLICK, play_);
function play_(event:Event):void {
if (!isPlaying) {
mySoundChannel = musicPiece.play(pos);
isPlaying = true;
}
}
pause_btn.addEventListener(MouseEvent.CLICK, pause_);
function pause_(event:Event):void {
if (isPlaying) {
pos = mySoundChannel.position;
mySoundChannel.stop();
isPlaying = false;
}
}
stop_btn.addEventListener(MouseEvent.CLICK, stop_);
function stop_(event:Event):void {
if (mySoundChannel != null) {
mySoundChannel.stop();
pos = 0;
isPlaying = false;
}
}
var rectangle:Rectangle = new Rectangle(0,0,100,0);
var dragging:Boolean = false;
volume_mc.mySlider_mc.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
function startDragging(event:Event):void {
volume_mc.mySlider_mc.startDrag(false,rectangle);
dragging = true;
volume_mc.mySlider_mc.addEventListener(Event.ENTER_FRAME, adjustVolume);
}
function adjustVolume(event:Event):void {
var myVol:Number = volume_mc.mySlider_mc.x / 100;
var mySoundTransform:SoundTransform = new SoundTransform(myVol);
if (mySoundChannel != null) {
mySoundChannel.soundTransform = mySoundTransform;
}
}
stage.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
function stopDragging(event:Event):void {
if (dragging) {
dragging = false;
volume_mc.mySlider_mc.stopDrag();
}
}
答案 0 :(得分:0)
语法错误正如它所说的那样,代码没有正确编写。例如,您在URLREquest
之后不应该有下划线var musicPiece:Sound = new Sound(new URLRequest("http://blog.0tutor.com/JeffWofford_Trouble.mp3"));
从同一个地方开始应该被注释掉,因为它是一个注释,它不是变量或函数。
调用函数“play_”也不是很好的做法。如果您担心冲突,请将其称为soundPlay。
对pause_和stop _
的相同评论