2012-10-24 68 views
2

我需要做一個快進按鈕和倒帶按鈕我有一切事情只需要這兩個,即時通訊不知道如何做到這一點。也即時使用Flash,動作腳本3爲音樂播放器製作快進按鈕和快退按鈕?

我看了一堆的例子,但他們都做不同於我。這是我學會了如何裝載軌道,使播放和暫停按鈕,但林不知道如何添加繞和前進

這裏的方式是我迄今爲止

import flash.media.Sound; 
import flash.media.SoundChannel; 

import flash.net.URLRequest; 

import flash.events.MouseEvent; 
import flash.events.Event; 

var myChannel:SoundChannel = new SoundChannel; 
var track:Sound; 

var trackToLoad:String; 
var trackName:String; 
var trackTime:String; 




function stopTrack(e:MouseEvent) :void { 
     myChannel.stop(); 
} 

function reStartTrack(e:MouseEvent) :void { 
     myChannel.stop(); 
     myChannel = track.play(); 
} 


function playTrack(e:MouseEvent) :void { 
     switch(e.target.name) { 
    case "track1": 
    trackToLoad = "musicForImport/11 Everlong.mp3"; 
    trackName = "Foo Fighters • Everlong" 
    break; 

    case "track2": 
    trackToLoad = "musicForImport/02 War Is a Cemetery.mp3"; 
    trackName = "Gob • War is a Cemetery" 
    break; 

    case "track3": 
    trackToLoad = "musicForImport/03 The Wind Cries Mary [Stereo].mp3"; 
    trackName = "Jimi Hendrix • The Wind Cries Mary" 
    break; 

    case "track4": 
    trackToLoad = "musicForImport/03 Work.mp3"; 
    trackName = "Jimmy Eat World • Work" 
    break; 

    case "track5": 
    trackToLoad = "musicForImport/02 Jumpin' Jack Flash.mp3"; 
    trackName = "The Rolling Stones • Jumpin' Jack Flash" 
    break; 

    case "track6": 
    trackToLoad = "musicForImport/04 Don't Walk Away Eileen.mp3"; 
    trackName = "Sam Roberts • Don't Walk Away Eileen" 
    break; 

    case "track7": 
    trackToLoad = "musicForImport/Brace Yourself.mp3"; 
    trackName = "State of Us • Brace Yourself" 
    break; 

    case "track8": 
    trackToLoad = "musicForImport/02 Wrong Way.mp3"; 
    trackName = "Sublime • Wrong Way" 
    break; 

    case "track9": 
    trackToLoad = "musicForImport/04 Fat Lip.mp3"; 
    trackName = "Sum 41• Fat Lip" 
    break; 

    case "track10": 
    trackToLoad = "musicForImport/The Boys Are Back In Town.mp3"; 
    trackName = "Thin Lizzy • The Boys Are Back In Town" 
    break; 
} 

track = new Sound; 
track.load(new URLRequest(trackToLoad)); 
myChannel.stop(); 
myChannel = track.play(); 

displayTrackName.text = ":: " + trackName + " ::"; 
displayTrackName.x = 103; 
displayTrackName.y = 440; 
} 

track1.addEventListener(MouseEvent.CLICK, playTrack); 
track2.addEventListener(MouseEvent.CLICK, playTrack); 
track3.addEventListener(MouseEvent.CLICK, playTrack); 
track4.addEventListener(MouseEvent.CLICK, playTrack); 
track5.addEventListener(MouseEvent.CLICK, playTrack); 
track6.addEventListener(MouseEvent.CLICK, playTrack); 
track7.addEventListener(MouseEvent.CLICK, playTrack); 
track8.addEventListener(MouseEvent.CLICK, playTrack); 
track9.addEventListener(MouseEvent.CLICK, playTrack); 
track10.addEventListener(MouseEvent.CLICK, playTrack); 

stopTrackButton.addEventListener(MouseEvent.CLICK, stopTrack); 
playTrackButton.addEventListener(MouseEvent.CLICK, reStartTrack); 

回答

0

後退和前進功能通過定時器實現:

import flash.media.Sound; 
import flash.events.MouseEvent; 
import flash.utils.Timer; 
import flash.events.TimerEvent; 
import flash.media.SoundChannel; 

const REWIND_SPEED:int = 1000; 

var sound:Sound = new MySound(); 
var timer:Timer = new Timer(100); 
var soundChannel:SoundChannel; 
var oldSoundChannel:SoundChannel; 

soundChannel = sound.play(); 

rewindBtn.addEventListener(MouseEvent.CLICK, rewindBtn_clickHandler); 
stopRewindBtn.addEventListener(MouseEvent.CLICK, stopRewindBtn_clickHandler); 
timer.addEventListener(TimerEvent.TIMER, timer_timerHandler); 

function rewindBtn_clickHandler(event:MouseEvent):void 
{ 
timer.start(); 
} 


function stopRewindBtn_clickHandler(event:MouseEvent):void 
{ 
timer.stop(); 
} 

function timer_timerHandler(event:TimerEvent):void 
{ 
if (!soundChannel) 
    return; 

if (soundChannel.position == sound.length) 
{ 
    timer.stop(); 
} 
else 
{ 
     oldSoundChannel = soundChannel; 
    soundChannel = sound.play(oldSoundChannel.position + REWIND_SPEED); 
    oldSoundChannel.stop(); 
} 

}

+0

IM把它放在一個按鈕,所以我怎麼會去這樣做呢? – zac

+0

我已經更新了我的答案。 –

+0

感謝您的回答 – zac

相關問題