Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 Flash/Actionscript 3-嵌入式声音播放/停止?_Actionscript 3_Flash_Playback - Fatal编程技术网

Actionscript 3 Flash/Actionscript 3-嵌入式声音播放/停止?

Actionscript 3 Flash/Actionscript 3-嵌入式声音播放/停止?,actionscript-3,flash,playback,Actionscript 3,Flash,Playback,如何通过按钮在Flash/AS3中播放/停止嵌入式音乐文件 这就是我所拥有的: import flash.events.Event; import flash.events.MouseEvent; import flash.display.MovieClip; import flash.media.Sound; import flash.media.SoundChannel; var myMusic:Sound = new ThemeSong(); var channel:Sound

如何通过按钮在Flash/AS3中播放/停止嵌入式音乐文件

这就是我所拥有的:

import flash.events.Event;  
import flash.events.MouseEvent;
import flash.display.MovieClip;  
import flash.media.Sound;
import flash.media.SoundChannel;

var myMusic:Sound = new ThemeSong(); 
var channel:SoundChannel = myMusic.play();

startButton.addEventListener(MouseEvent.CLICK, onStartClick);
stopButton.addEventListener(MouseEvent.CLICK, onStopClick);

function onStartClick(event:MouseEvent):void{
    myMusic.play();
}

function onStopClick(event:MouseEvent):void{
    myMusic.stop();
}
ThemeSong是为音乐文件分配的类的名称(导入->库->属性->导出为AS->类名)。startButton和stopButton是按钮的标识符

如果我运行此命令,我将得到一个错误,提示:

"Scene 1, Layer 'actions', Frame 1, Line 69 1061: Call to a possibly undefined method stop through a reference with static type flash.media:Sound."

谢谢。

你差一点了,Flash有时会有问题:

import flash.events.Event;  
import flash.events.MouseEvent;
import flash.display.MovieClip;  
import flash.media.Sound;
import flash.media.SoundChannel;

var myMusic:Sound = new ThemeSong(); 
var channel:SoundChannel = myMusic.play();

startButton.addEventListener(MouseEvent.CLICK, onStartClick);
stopButton.addEventListener(MouseEvent.CLICK, onStopClick);

function onStartClick(event:MouseEvent):void{
    channel = myMusic.play();
}

function onStopClick(event:MouseEvent):void{
    channel.stop();
}

相信播放方法需要一段时间,所以当你停止播放时,你必须记录它已经播放了多长时间,然后在这段时间内调用播放(这有点痛苦)