2012-11-22 46 views
0

是否有可能?我對ActionScript 3 &相當陌生,一直在玩滑塊組件。我已經設置了一個帶有圖像的滑塊,並設置了一個聲音來播放,所以如果該值大於0,它將播放,如果大於4,它將停止播放。但是當我輸出它時,它沒有出現任何錯誤。我相信我必須改變event.value的東西,而不是數字。或者更確切地說,使用另一個事件,但我不確定..所以我會假設,如果你在這些圖像之間的側面,MP3會繼續播放,而不是重新啓動它擊中的每個值。這是我AS3播放滑塊上的聲音值


function changeHandler(event:SliderEvent):void { 
     aLoader.source = "pic"+event.value+".jpeg"; 

} 

function music(event:SliderEvent):void { 
    var mySound:Sound = new tes1(); 
    var myChannel:SoundChannel = new SoundChannel(); 
    mySound.load(new URLRequest("tes1.mp3")); 





     if (event.value > 0 || event.value > 4){ 
      myChannel = mySound.play(); 
     } 

     else{ 
      myChannel.stop(); 
     } 
} 

回答

0

你正在創建在每個滑塊事件的新聲道,如果該值所需的範圍之外,停止新的聲道。但它並沒有發出任何聲音開始。

你可能想要的是存儲事件處理程序之外的聲道,而當值的範圍內跳也許不是重播的聲音:

slider.addEventListener(SliderEvent.CHANGE, music); 

// Stores the sound channel between slider movements. 
var myChannel:SoundChannel = new SoundChannel(); 
var isPlaying:Boolean = false; 

function music(event:SliderEvent):void { 
    var mySound:Sound = new tes1(); 
    mySound.load(new URLRequest("tes1.mp3")); 

    if (event.value > 0 || event.value > 4) { 

     // Check if we are already playing the sound and, if yes, do nothing 
     if (!isPlaying) { 
      myChannel = mySound.play(); 
      isPlaying = true; 
     } 

    } else { 
     myChannel.stop(); 
     isPlaying = false; 
    } 
} 

所以,當值獲得所需的範圍之外,它停止播放最後一個聲音,並且當該值在範圍內移動時,它將繼續播放而不是重新啓動。

+0

非常感謝BoppreH! ;)現在變得更有意義。雖然我想弄錯了一個錯誤。錯誤:錯誤#2037:以不正確的順序或更早的調用調用的函數不成功。 \t在flash.media::Sound/_load() \t在flash.media::Sound/load() \t在sc_fla :: MainTimeline /音樂() \t在flash.events::EventDispatcher/dispatchEventFunction() ()) \t at flash.events::EventDispatcher/dispatchEvent() \t at fl.controls :: Slider/thumbReleaseHandler() – user1810771