2017-08-06 173 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