2017-08-06 169 views
0

帮助我,我使用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. 
+0

PS:'VAR陈:的SoundChannel = snd.play();'是行不通的,因为你没有实例化'chan'为** *新*类型_SoundChannel_的变量。它应该是:'var chan:SoundChannel = new SoundChannel();'然后你可以用'chan = snd.play();' –

+0

@ VC.One来追踪它,'play()'创建一个新的'SoundChannel'目的。 – Vesper

+0

@Vesper我期待'var snd:Sound = new Sound(); snd.play();'工作,但你能解释为什么asker的代码'var chan:SoundChannel = snd.play();'不工作? –

回答

2

我只是在youtube上观看,我错过了一步。 在图书馆中,打开music.mp3的属性并为其命名。

enter image description here

所以,我们可以调用使用这个var Audio:musik=new musik();类。 然后,创建声音通道。 至少,功能的发挥,并停止使用此:

//play 
chan=Audio.play(); 
// stop 
chan.stop(); 
+0

您刚刚将MP3嵌入到SWF中,而不是在SWF启动后动态加载它。适用于小型/呃资源,不适用于大型/呃资源和动态资源集。如果您打算在加载的资源中更改内容,则最好使用URL加载。 – Vesper