动作脚本3:卡拉OK播放器 - 在重播时,音乐不会重新开始,只有文字

时间:2011-10-18 08:03:40

标签: flash actionscript-3 actionscript flash-cs5

我遇到了Action Script 3的问题。我使用的是Flash CS5。

我想创建一个小卡拉OK播放器。它适用于第一场比赛,但不适用于第二场比赛。

在第一层我有我的播放器(音乐,按钮等)。使用播放按钮,我启动音频(mp3)和歌词(文本)。我将文本称为实例(它是主层的子层)。

问题是,当我完成歌曲和文本并想再次播放时,只会播放文字而不是音乐。

我怎样才能加载音乐?

这是我的代码:

// Musik
var meinSound = new musik ();
var meinSoundKanal = meinSound.play ();
var meinSoundTransform = meinSoundKanal.soundTransform;
meinSoundKanal.stop ();
var soundPosition = 0;

// Play und Pause Button
var buttonZustand = "Play";

this.play_bt.addEventListener (MouseEvent.CLICK, buttonAendern);
function buttonAendern (Param) {
    if (buttonZustand == "Play") {
        this.play_bt.gotoAndStop (2);
        buttonZustand = "Pause";
        meinSoundKanal = meinSound.play (soundPosition);
        meinSoundKanal.soundTransform = meinSoundTransform;
        this.textanimation.play();
    } else {
        this.play_bt.gotoAndStop (1);
        buttonZustand = "Play";
        soundPosition = meinSoundKanal.position;
        meinSoundKanal.stop();
        this.textanimation.stop();
    }
}

// Volume Button
var volumeZustand = "An";

this.volume_bt.addEventListener (MouseEvent.CLICK, volumeAendern);
function volumeAendern (Param) {
    if (volumeZustand == "An") {
        this.volume_bt.gotoAndStop (2);
        volumeZustand = "Aus";
        meinSoundTransform.volume = 0;
        meinSoundKanal.soundTransform = meinSoundTransform;
    } else {
        volumeZustand = "An";
        this.volume_bt.gotoAndStop (1);
        meinSoundTransform.volume = 1;
        meinSoundKanal.soundTransform = meinSoundTransform;
    }
}

// Stop Button
this.stop_bt.addEventListener(MouseEvent.CLICK, LiedStoppen);
function LiedStoppen (e) {
    meinSoundKanal.stop();
    play_bt.gotoAndStop(1)
    this.textanimation.gotoAndStop(1)
}

// Lautstärkeregler
var bewegungsRaum=new Rectangle(361,357,168,0);

this.regler_bt.addEventListener(MouseEvent.MOUSE_DOWN, halten);

function halten(Parameter)
{
    this.regler_bt.startDrag(false, bewegungsRaum);
}

this.regler_bt.addEventListener(MouseEvent.MOUSE_UP, loslassen);

function loslassen(Parameter)
{
    this.regler_bt.stopDrag();
}


this.regler_bt.addEventListener(MouseEvent.MOUSE_MOVE, lautRegeln);
function lautRegeln(Param) {
    meinSoundTransform.volume = (this.regler_bt.x -361) / 168;
    meinSoundKanal.soundTransform = meinSoundTransform;
}

我希望你能帮助我:)。

迎接


更新:

// Musik
var meinSound = new musik ();
var meinSoundKanal = meinSound.play ();
var meinSoundTransform = meinSoundKanal.soundTransform;
meinSoundKanal.stop ();
var soundPosition = 0;

meinSoundKanal.addEventListener(Event.SOUND_COMPLETE, next_item_handler);
        function next_item_handler(e:Event):void{
         meinSoundKanal.stop();
         soundPosition = meinSoundKanal.position;
    }


// Play und Pause Button
var buttonZustand = "Play";

this.play_bt.addEventListener (MouseEvent.CLICK, buttonAendern);
function buttonAendern (Param) {
    if (buttonZustand == "Play") {
        this.play_bt.gotoAndStop (2);
        buttonZustand = "Pause";
        meinSoundKanal = meinSound.play (soundPosition);
        meinSoundKanal.soundTransform = meinSoundTransform;
        this.textanimation.play();
    } else {
        this.play_bt.gotoAndStop (1);
        buttonZustand = "Play";
        soundPosition = meinSoundKanal.position;
        meinSoundKanal.stop();
        this.textanimation.stop();
    }
}



// Volume Button
var volumeZustand = "An";

this.volume_bt.addEventListener (MouseEvent.CLICK, volumeAendern);
function volumeAendern (Param) {
    if (volumeZustand == "An") {
        this.volume_bt.gotoAndStop (2);
        volumeZustand = "Aus";
        meinSoundTransform.volume = 0;
        meinSoundKanal.soundTransform = meinSoundTransform;
    } else {
        volumeZustand = "An";
        this.volume_bt.gotoAndStop (1);
        meinSoundTransform.volume = 1;
        meinSoundKanal.soundTransform = meinSoundTransform;
    }
}

// Stop Button
this.stop_bt.addEventListener(MouseEvent.CLICK, LiedStoppen);
function LiedStoppen (e) {
    meinSoundKanal.stop();
    play_bt.gotoAndStop(1)
    this.textanimation.gotoAndStop(1)
}

// Lautstärkeregler
var bewegungsRaum=new Rectangle(361,357,168,0);

this.regler_bt.addEventListener(MouseEvent.MOUSE_DOWN, halten);

function halten(Parameter)
{
    this.regler_bt.startDrag(false, bewegungsRaum);
}

this.regler_bt.addEventListener(MouseEvent.MOUSE_UP, loslassen);

function loslassen(Parameter)
{
    this.regler_bt.stopDrag();
}


this.regler_bt.addEventListener(MouseEvent.MOUSE_MOVE, lautRegeln);
function lautRegeln(Param) {
    meinSoundTransform.volume = (this.regler_bt.x -361) / 168;
    meinSoundKanal.soundTransform = meinSoundTransform;
}

再次更新:D

// Musik
var meinSound = new musik ();
var meinSoundKanal = meinSound.play ();
var meinSoundTransform = meinSoundKanal.soundTransform;
meinSoundKanal.stop ();
var soundPosition = 0;

meinSoundKanal.addEventListener(Event.SOUND_COMPLETE, next_item_handler);
    function next_item_handler(e:Event):void{
          var soundPosition = 0; 
          var meinSoundKanal = meinSound.play ();
    }


// Play und Pause Button
var buttonZustand = "Play";

this.play_bt.addEventListener (MouseEvent.CLICK, buttonAendern);
function buttonAendern (Param) {
    if (buttonZustand == "Play") {
        this.play_bt.gotoAndStop (2);
        buttonZustand = "Pause";
        meinSoundKanal = meinSound.play (soundPosition);
        meinSoundKanal.soundTransform = meinSoundTransform;
        this.textanimation.play();
    } else {
        this.play_bt.gotoAndStop (1);
        buttonZustand = "Play";
        soundPosition = meinSoundKanal.position;
        meinSoundKanal.stop();
        this.textanimation.stop();
    }
}

// Volume Button
var volumeZustand = "An";

this.volume_bt.addEventListener (MouseEvent.CLICK, volumeAendern);
function volumeAendern (Param) {
    if (volumeZustand == "An") {
        this.volume_bt.gotoAndStop (2);
        volumeZustand = "Aus";
        meinSoundTransform.volume = 0;
        meinSoundKanal.soundTransform = meinSoundTransform;
    } else {
        volumeZustand = "An";
        this.volume_bt.gotoAndStop (1);
        meinSoundTransform.volume = 1;
        meinSoundKanal.soundTransform = meinSoundTransform;
    }
}

// Stop Button
this.stop_bt.addEventListener(MouseEvent.CLICK, LiedStoppen);
function LiedStoppen (e) {
    meinSoundKanal.stop();
    play_bt.gotoAndStop(1)
    this.textanimation.gotoAndStop(1)
}

// Lautstärkeregler
var bewegungsRaum=new Rectangle(361,357,168,0);

this.regler_bt.addEventListener(MouseEvent.MOUSE_DOWN, halten);

function halten(Parameter)
{
    this.regler_bt.startDrag(false, bewegungsRaum);
}

this.regler_bt.addEventListener(MouseEvent.MOUSE_UP, loslassen);

function loslassen(Parameter)
{
    this.regler_bt.stopDrag();
}


this.regler_bt.addEventListener(MouseEvent.MOUSE_MOVE, lautRegeln);
function lautRegeln(Param) {
    meinSoundTransform.volume = (this.regler_bt.x -361) / 168;
    meinSoundKanal.soundTransform = meinSoundTransform;
}

1 个答案:

答案 0 :(得分:0)

您应该使用soundChannel课来检查音频是否已完成播放。

SndChannel.addEventListener(Event.SOUND_COMPLETE, next_item_handler);
    private function next_item_handler(e:Event):void{
         //location for next or prev or repeat link.
    }