如何通过按钮在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是我为音乐文件指定的类的名称(import - > libraries - > properties - > export for AS - > class name)。 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."
感谢。
答案 0 :(得分:0)
你很接近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();
}