2008-09-16 92 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 =不确定;

这应该做到这一点。