2008-09-16 94 views
1

我有一個flash播放器,其中有一組歌曲通過xml文件加載。如何在流模式下阻止MP3文件被Flash下載

文件不會開始獲取流,直到你選擇一個。

如果我快速循環瀏覽8個文件中的每一個,則閃存開始嘗試同時下載這8個文件中的每一個。

我想知道是否有一種方法來清除正在下載的文件。所以如果有人決定點擊大量音軌名稱,帶寬不會被吃掉。

喜歡的東西mySound.clear將是巨大的,或者mySound.stopStreaming ..

有沒有人有這個問題?

問候,

克里斯

+0

這是動作2還是3? – grapefrukt 2008-09-16 19:29:16

回答

1

結賬Sound.Close()

從文檔:「關閉該流,從而導致數據停止的任何下載任何數據可從流中close()方法被調用後讀。」

這是source code example從鏈接的文檔:

package { 
    import flash.display.Sprite; 
    import flash.net.URLRequest; 
    import flash.media.Sound;  
    import flash.text.TextField; 
    import flash.text.TextFieldAutoSize; 
    import flash.events.MouseEvent; 
    import flash.errors.IOError; 
    import flash.events.IOErrorEvent; 

    public class Sound_closeExample extends Sprite { 
     private var snd:Sound = new Sound(); 
     private var button:TextField = new TextField(); 
     private var req:URLRequest = new URLRequest("http://av.adobe.com/podcast/csbu_dev_podcast_epi_2.mp3"); 

     public function Sound_closeExample() { 
      button.x = 10; 
      button.y = 10; 
      button.text = "START"; 
      button.border = true; 
      button.background = true; 
      button.selectable = false; 
      button.autoSize = TextFieldAutoSize.LEFT; 

      button.addEventListener(MouseEvent.CLICK, clickHandler); 

      this.addChild(button); 
     } 

     private function clickHandler(e:MouseEvent):void { 

      if(button.text == "START") { 

       snd.load(req); 
       snd.play();   

       snd.addEventListener(IOErrorEvent.IO_ERROR, errorHandler); 

       button.text = "STOP"; 
      } 
      else if(button.text == "STOP") { 

       try { 
        snd.close(); 
        button.text = "Wait for loaded stream to finish."; 
       } 
       catch (error:IOError) { 
        button.text = "Couldn't close stream " + error.message;  
       } 
      } 
     } 

     private function errorHandler(event:IOErrorEvent):void { 
       button.text = "Couldn't load the file " + event.text; 
     } 
    } 
} 
0

如果你做這樣的事情:

MySoundObject =不確定;

這應該做到這一點。