帮助我,我使用Adobe Flash CS3 Professional。ActionScript 3 - 没有错误播放声音的mp3
// i have try using this import, but still not work
/*import flash.events.Event;
import flash.media.Sound;
import flash.net.URLRequest;
*/
// here is the code
var req:URLRequest=new URLRequest("music.mp3");
var snd:Sound=new Sound();
snd.load(req);
var chan:SoundChannel=snd.play();// not work using 'snd.play(1);' too
chan.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
function onPlaybackComplete(event:Event){
trace("Musik Complete");
}
当我运行的SWF或ctrl+enter
,输出Musik Complete
没有任何声音出场,但动画还在上演。对于动画我只是创建简单的双胞胎动作。
我这个目录
C:/flash/example.fla
C:/flash/example.swf
C:/flash/music.mp3
我尝试导入music.mp3
到库太上工作。
注意:我从我的朋友(.swf,.fla,.mp3)得到了这个例子。我播放由我的朋友和工作人员共享的.swf文件,但是当我尝试通过自己创建时,这不起作用。所以,我认为music.mp3
适用于Flash。这里是我的朋友代码:
var Audio:musik = new musik();
var chan:SoundChannel = new SoundChannel();
// play
chan=Audio.play();
// stop
chan.stop();
// i am so confuse i run my friend project and work fine (sound and other), if i write from scrap even i write the same code, there is an error, and this the error:
// 1046: Type was not found or was not a compile-time constant: musik.
// 1180: Call to a possibly undefined method musik.
PS:'VAR陈:的SoundChannel = snd.play();'是行不通的,因为你没有实例化'chan'为** *新*类型_SoundChannel_的变量。它应该是:'var chan:SoundChannel = new SoundChannel();'然后你可以用'chan = snd.play();' –
@ VC.One来追踪它,'play()'创建一个新的'SoundChannel'目的。 – Vesper
@Vesper我期待'var snd:Sound = new Sound(); snd.play();'工作,但你能解释为什么asker的代码'var chan:SoundChannel = snd.play();'不工作? –