Avatar billede Vivivroue Nybegynder
08. april 2011 - 12:41 Der er 11 kommentarer og
1 løsning

Musik afspiller. Actionscript. Skal kun være muligt at trykke play én gang.

Hej.

Prøv at se dette link.

http://vivid-design.dk/masja/Flash/FullMasja.html

Pause, play, og stop -virker fint.

MEN når man trykker play flere gange, overlapper sangene hinanden, og det er ikke muligt at stoppe det hele igen.

Kan I hjælpe mig med, at finde ud af hvad jeg konkret skal skrive i min actionscript for at løse dette problem?

Actionscriptet ser således ud.

SoundMixer.stopAll()
var mySound:Sound = new Sound();
var songURL:URLRequest = new URLRequest("Dreaming.mp3");
var channel1:SoundChannel = new SoundChannel();
var resumeTime:Number = 0;
mySound.load(songURL);
play_btn.addEventListener(MouseEvent.CLICK, playSound);
pause_btn.addEventListener(MouseEvent.CLICK, pauseSound);
stop_btn.addEventListener(MouseEvent.CLICK, stopSound);
function playSound(e:MouseEvent):void {
    channel1 = mySound.play(resumeTime)
}
function pauseSound(e:MouseEvent):void {
    resumeTime = channel1.position;
    channel1.stop();
}
function stopSound(e:MouseEvent):void {
    channel1.stop();
    resumeTime = 0;
}
var mySound2:Sound = new Sound();
var songURL2:URLRequest = new URLRequest("WingsOfAnEagle.mp3");
var channel2:SoundChannel = new SoundChannel();
var resumeTime2:Number = 0;
mySound2.load(songURL2);
play_btn2.addEventListener(MouseEvent.CLICK, playSound2);
pause_btn2.addEventListener(MouseEvent.CLICK, pauseSound2);
stop_btn2.addEventListener(MouseEvent.CLICK, stopSound2);
function playSound2(e:MouseEvent):void {
    channel2 = mySound2.play(resumeTime)
}
function pauseSound2(e:MouseEvent):void {
    resumeTime = channel2.position;
    channel2.stop();
}
function stopSound2(e:MouseEvent):void {
    channel2.stop();
    resumeTime = 0;
}
var mySound3:Sound = new Sound();
var songURL3:URLRequest = new URLRequest("FragilenYoung.mp3");
var channel3:SoundChannel = new SoundChannel();
var resumeTime3:Number = 0;
mySound3.load(songURL3);
play_btn3.addEventListener(MouseEvent.CLICK, playSound3);
pause_btn3.addEventListener(MouseEvent.CLICK, pauseSound3);
stop_btn3.addEventListener(MouseEvent.CLICK, stopSound3);
function playSound3(e:MouseEvent):void {
    channel3 = mySound3.play(resumeTime)
}
function pauseSound3(e:MouseEvent):void {
    resumeTime = channel3.position;
    channel3.stop();
}
function stopSound3(e:MouseEvent):void {
    channel3.stop();
    resumeTime = 0;
}
var mySound4:Sound = new Sound();
var songURL4:URLRequest = new URLRequest("InLove.mp3");
var channel4:SoundChannel = new SoundChannel();
var resumeTime4:Number = 0;
mySound4.load(songURL4);
play_btn4.addEventListener(MouseEvent.CLICK, playSound4);
pause_btn4.addEventListener(MouseEvent.CLICK, pauseSound4);
stop_btn4.addEventListener(MouseEvent.CLICK, stopSound4);
function playSound4(e:MouseEvent):void {
    channel4 = mySound4.play(resumeTime)
}
function pauseSound4(e:MouseEvent):void {
    resumeTime = channel4.position;
    channel4.stop();
}
function stopSound4(e:MouseEvent):void {
    channel4.stop();
    resumeTime = 0;
}


buy_btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage_2);

function fl_ClickToGoToWebPage_2(event:MouseEvent):void
{
    navigateToURL(new URLRequest("http://www.gdc.dk/enduser/shop.aml?shop=4157498"), "_blank");
}
Avatar billede iver_mo Nybegynder
08. april 2011 - 19:57 #1
Jeg har sat en variabel ind så den tjekker om der allerede er et nummer der spiller. Hvis der er sker der intet ved at klikke på play.

Vær opmærksom på at du skal trykke på pause eller stop på et igangværende nummer før du kan trykke på play på en af de andre numre.



Erstat den kode du vist med denne:


------------------------------------------



var music_om = 0

SoundMixer.stopAll()
var mySound:Sound = new Sound();
var songURL:URLRequest = new URLRequest("Dreaming.mp3");
var channel1:SoundChannel = new SoundChannel();
var resumeTime:Number = 0;
mySound.load(songURL);
play_btn.addEventListener(MouseEvent.CLICK, playSound);
pause_btn.addEventListener(MouseEvent.CLICK, pauseSound);
stop_btn.addEventListener(MouseEvent.CLICK, stopSound);


function playSound1(e:MouseEvent):void {
    if (music_on == 0) {
        channel1 = mySound1.play(resumeTime)
        music_on = 1
    }
}

function pauseSound1(e:MouseEvent):void {
    resumeTime = channel1.position;
    channel1.stop();
    music_on = 0
}

function stopSound1(e:MouseEvent):void {
    channel1.stop();
    resumeTime = 0;
    music_on = 0
}


var mySound2:Sound = new Sound();
var songURL2:URLRequest = new URLRequest("WingsOfAnEagle.mp3");
var channel2:SoundChannel = new SoundChannel();
var resumeTime2:Number = 0;
mySound2.load(songURL2);
play_btn2.addEventListener(MouseEvent.CLICK, playSound2);
pause_btn2.addEventListener(MouseEvent.CLICK, pauseSound2);
stop_btn2.addEventListener(MouseEvent.CLICK, stopSound2);

function playSound2(e:MouseEvent):void {
    if (music_on == 0) {
        channel2 = mySound2.play(resumeTime)
        music_on = 1
    }
}

function pauseSound2(e:MouseEvent):void {
    resumeTime = channel2.position;
    channel2.stop();
    music_on = 0
}

function stopSound2(e:MouseEvent):void {
    channel2.stop();
    resumeTime = 0;
    music_on = 0
}


var mySound3:Sound = new Sound();
var songURL3:URLRequest = new URLRequest("FragilenYoung.mp3");
var channel3:SoundChannel = new SoundChannel();
var resumeTime3:Number = 0;
mySound3.load(songURL3);
play_btn3.addEventListener(MouseEvent.CLICK, playSound3);
pause_btn3.addEventListener(MouseEvent.CLICK, pauseSound3);
stop_btn3.addEventListener(MouseEvent.CLICK, stopSound3);


function playSound3(e:MouseEvent):void {
    if (music_on == 0) {
        channel3 = mySound3.play(resumeTime)
        music_on = 1
    }
}

function pauseSound3(e:MouseEvent):void {
    resumeTime = channel3.position;
    channel3.stop();
    music_on = 0
}

function stopSound3(e:MouseEvent):void {
    channel3.stop();
    resumeTime = 0;
    music_on = 0
}


var mySound4:Sound = new Sound();
var songURL4:URLRequest = new URLRequest("InLove.mp3");
var channel4:SoundChannel = new SoundChannel();
var resumeTime4:Number = 0;
mySound4.load(songURL4);
play_btn4.addEventListener(MouseEvent.CLICK, playSound4);
pause_btn4.addEventListener(MouseEvent.CLICK, pauseSound4);
stop_btn4.addEventListener(MouseEvent.CLICK, stopSound4);

function playSound4(e:MouseEvent):void {
    if (music_on == 0) {
        channel4 = mySound4.play(resumeTime)
        music_on = 1
    }
}

function pauseSound4(e:MouseEvent):void {
    resumeTime = channel4.position;
    channel4.stop();
    music_on = 0
}

function stopSound4(e:MouseEvent):void {
    channel4.stop();
    resumeTime = 0;
    music_on = 0
}



buy_btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage_2);

function fl_ClickToGoToWebPage_2(event:MouseEvent):void
{
    navigateToURL(new URLRequest("http://www.gdc.dk/ (...)), "_blank");
}
Avatar billede Vivivroue Nybegynder
08. april 2011 - 20:03 #2
Suuuuuper dejligt med et konkret svar :)

Jeg tester det lige..
Avatar billede Vivivroue Nybegynder
08. april 2011 - 20:06 #3
Det går helt galt med den kode. Min intro går f amok, og gentager sig selv om og om igen. Derfra kan jeg ikke komme videre.

Hmmm..
Avatar billede Vivivroue Nybegynder
08. april 2011 - 20:07 #4
Får også disse fejlbeskeder:

Symbol 'music', Layer 'Actions', Frame 1, Line 127    1084: Syntax error: expecting rightparen before _blank.
Symbol 'music', Layer 'Actions', Frame 1, Line 127    1095: Syntax error: A string literal must be terminated before the line break.
Symbol 'music', Layer 'Actions', Frame 1, Line 127    1084: Syntax error: expecting rightbrace before _blank.
Avatar billede iver_mo Nybegynder
08. april 2011 - 20:14 #5
Lidt ændringer: Hvis en sang spiller og man trykker play på en anden sang så stoppes den igangværende sang og den nye sang starter.

Erstat koden med:

---------------------------------------------------

var music_om = 0
var temp_id = 0

SoundMixer.stopAll()
var mySound:Sound = new Sound();
var songURL:URLRequest = new URLRequest("Dreaming.mp3");
var channel1:SoundChannel = new SoundChannel();
var resumeTime:Number = 0;
mySound.load(songURL);
play_btn.addEventListener(MouseEvent.CLICK, playSound);
pause_btn.addEventListener(MouseEvent.CLICK, pauseSound);
stop_btn.addEventListener(MouseEvent.CLICK, stopSound);


function playSound1(e:MouseEvent):void {
    if ((music_on == 0) || (temp_id != 1)) {
        channel2.stop();
        channel3.stop();
        channel4.stop();
        channel1 = mySound1.play(resumeTime);
        music_on = 1;
        temp_id = 1;
    }
}

function pauseSound1(e:MouseEvent):void {
    resumeTime = channel1.position;
    channel1.stop();
    music_on = 0;
    temp_id = 0;
}

function stopSound1(e:MouseEvent):void {
    channel1.stop();
    resumeTime = 0;
    music_on = 0;
    temp_id = 0;
}


var mySound2:Sound = new Sound();
var songURL2:URLRequest = new URLRequest("WingsOfAnEagle.mp3");
var channel2:SoundChannel = new SoundChannel();
var resumeTime2:Number = 0;
mySound2.load(songURL2);
play_btn2.addEventListener(MouseEvent.CLICK, playSound2);
pause_btn2.addEventListener(MouseEvent.CLICK, pauseSound2);
stop_btn2.addEventListener(MouseEvent.CLICK, stopSound2);

function playSound2(e:MouseEvent):void {
    if ((music_on == 0) || (temp_id != 2)) {
        channel1.stop();
        channel3.stop();
        channel4.stop();
        channel2 = mySound2.play(resumeTime);
        music_on = 1;
        temp_id = 2;
    }
}

function pauseSound2(e:MouseEvent):void {
    resumeTime = channel2.position;
    channel2.stop();
    music_on = 0;
    temp_id = 0;
}

function stopSound2(e:MouseEvent):void {
    channel2.stop();
    resumeTime = 0;
    music_on = 0;
    temp_id = 0;
}


var mySound3:Sound = new Sound();
var songURL3:URLRequest = new URLRequest("FragilenYoung.mp3");
var channel3:SoundChannel = new SoundChannel();
var resumeTime3:Number = 0;
mySound3.load(songURL3);
play_btn3.addEventListener(MouseEvent.CLICK, playSound3);
pause_btn3.addEventListener(MouseEvent.CLICK, pauseSound3);
stop_btn3.addEventListener(MouseEvent.CLICK, stopSound3);


function playSound3(e:MouseEvent):void {
    if ((music_on == 0) || (temp_id != 3)) {
        channel1.stop();
        channel2.stop();
        channel4.stop();
        channel3 = mySound3.play(resumeTime);
        music_on = 1;
        temp_id = 3;
    }
}

function pauseSound3(e:MouseEvent):void {
    resumeTime = channel3.position;
    channel3.stop();
    music_on = 0;
    temp_id = 0;
}

function stopSound3(e:MouseEvent):void {
    channel3.stop();
    resumeTime = 0;
    music_on = 0;
    temp_id = 0;
}


var mySound4:Sound = new Sound();
var songURL4:URLRequest = new URLRequest("InLove.mp3");
var channel4:SoundChannel = new SoundChannel();
var resumeTime4:Number = 0;
mySound4.load(songURL4);
play_btn4.addEventListener(MouseEvent.CLICK, playSound4);
pause_btn4.addEventListener(MouseEvent.CLICK, pauseSound4);
stop_btn4.addEventListener(MouseEvent.CLICK, stopSound4);

function playSound4(e:MouseEvent):void {
    if ((music_on == 0) || (temp_id != 4)) {
        channel1.stop();
        channel2.stop();
        channel3.stop();
        channel4 = mySound4.play(resumeTime);
        music_on = 1;
        temp_id = 4;
    }
}

function pauseSound4(e:MouseEvent):void {
    resumeTime = channel4.position;
    channel4.stop();
    music_on = 0;
    temp_id = 0;
}

function stopSound4(e:MouseEvent):void {
    channel4.stop();
    resumeTime = 0;
    music_on = 0;
    temp_id = 0;
}



buy_btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage_2);

function fl_ClickToGoToWebPage_2(event:MouseEvent):void
{
    navigateToURL(new URLRequest("http://www.gdc.dk/ (...)), "_blank");
}
Avatar billede iver_mo Nybegynder
08. april 2011 - 20:22 #6
Jeg har fundet en fejl - Lidt for frisk i min substitution :-( poster om lidt igen.
Avatar billede iver_mo Nybegynder
08. april 2011 - 20:42 #7
Så prøver vi igen:

-------------------------------------------------


var music_om = 0;
var temp_id = 0;

SoundMixer.stopAll();
var mySound:Sound = new Sound();
var songURL:URLRequest = new URLRequest("Dreaming.mp3");
var channel1:SoundChannel = new SoundChannel();
var resumeTime:Number = 0;
mySound.load(songURL);
play_btn.addEventListener(MouseEvent.CLICK, playSound);
pause_btn.addEventListener(MouseEvent.CLICK, pauseSound);
stop_btn.addEventListener(MouseEvent.CLICK, stopSound);

function playSound(e:MouseEvent):void {
    if ((music_on == 0) || (temp_id != 1)) {
        channel2.stop();
        channel3.stop();
        channel4.stop();
        channel1 = mySound.play(resumeTime);
        music_on = 1;
        temp_id = 1;
    }
}

function pauseSound(e:MouseEvent):void {
    resumeTime = channel1.position;
    channel1.stop();
    music_on = 0;
    temp_id = 0;
}

function stopSound(e:MouseEvent):void {
    channel1.stop();
    resumeTime = 0;
    music_on = 0;
    temp_id = 0;
}

var mySound2:Sound = new Sound();
var songURL2:URLRequest = new URLRequest("WingsOfAnEagle.mp3");
var channel2:SoundChannel = new SoundChannel();
var resumeTime2:Number = 0;
mySound2.load(songURL2);
play_btn2.addEventListener(MouseEvent.CLICK, playSound2);
pause_btn2.addEventListener(MouseEvent.CLICK, pauseSound2);
stop_btn2.addEventListener(MouseEvent.CLICK, stopSound2);

function playSound2(e:MouseEvent):void {
    if ((music_on == 0) || (temp_id != 2)) {
        channel1.stop();
        channel3.stop();
        channel4.stop();
        channel2 = mySound2.play(resumeTime2);
        music_on = 1;
        temp_id = 2;
    }
}

function pauseSound2(e:MouseEvent):void {
    resumeTime2 = channel2.position;
    channel2.stop();
    music_on = 0;
    temp_id = 0;
}

function stopSound2(e:MouseEvent):void {
    channel2.stop();
    resumeTime2 = 0;
    music_on = 0;
    temp_id = 0;
}

var mySound3:Sound = new Sound();
var songURL3:URLRequest = new URLRequest("FragilenYoung.mp3");
var channel3:SoundChannel = new SoundChannel();
var resumeTime3:Number = 0;
mySound3.load(songURL3);
play_btn3.addEventListener(MouseEvent.CLICK, playSound3);
pause_btn3.addEventListener(MouseEvent.CLICK, pauseSound3);
stop_btn3.addEventListener(MouseEvent.CLICK, stopSound3);

function playSound3(e:MouseEvent):void {
    if ((music_on == 0) || (temp_id != 3)) {
        channel1.stop();
        channel2.stop();
        channel4.stop();
        channel3 = mySound3.play(resumeTime3);
        music_on = 1;
        temp_id = 2;
    }
}

function pauseSound3(e:MouseEvent):void {
    resumeTime3 = channel3.position;
    channel3.stop();
    music_on = 0;
    temp_id = 0;
}

function stopSound3(e:MouseEvent):void {
    channel3.stop();
    resumeTime3 = 0;
    music_on = 0;
    temp_id = 0;
}


var mySound4:Sound = new Sound();
var songURL4:URLRequest = new URLRequest("InLove.mp3");
var channel4:SoundChannel = new SoundChannel();
var resumeTime4:Number = 0;
mySound4.load(songURL4);
play_btn4.addEventListener(MouseEvent.CLICK, playSound4);
pause_btn4.addEventListener(MouseEvent.CLICK, pauseSound4);
stop_btn4.addEventListener(MouseEvent.CLICK, stopSound4);


function playSound4(e:MouseEvent):void {
    if ((music_on == 0) || (temp_id != 4)) {
        channel1.stop();
        channel2.stop();
        channel3.stop();
        channel4 = mySound4.play(resumeTime4);
        music_on = 1;
        temp_id = 2;
    }
}

function pauseSound4(e:MouseEvent):void {
    resumeTime4 = channel4.position;
    channel4.stop();
    music_on = 0;
    temp_id = 0;
}

function stopSound4(e:MouseEvent):void {
    channel4.stop();
    resumeTime4 = 0;
    music_on = 0;
    temp_id = 0;
}


buy_btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage_2);

function fl_ClickToGoToWebPage_2(event:MouseEvent):void
{
    navigateToURL(new URLRequest("http://www.gdc.dk/ (...)), "_blank");
}
Avatar billede Vivivroue Nybegynder
08. april 2011 - 20:47 #8
Samme resultat. Måske det er en for svær opgaven når du ikke har hele filen?
Avatar billede iver_mo Nybegynder
08. april 2011 - 20:48 #9
Ja, det tror jeg desværre :(
Avatar billede Vivivroue Nybegynder
08. april 2011 - 20:51 #10
Øv det var en skam :(
Avatar billede iver_mo Nybegynder
09. april 2011 - 21:54 #11
hmmm... flovt. Det er gået op for mig at der tale om et flash actionscript og ikke JavaScript :-(

Jeg har lige kigget lidt på syntaksen og det ser ud til at det kan fixes med nogle små ændringer.

Jeg poster et sidste forsøg om et par dage (har ikke tid til at kigge ordentligt på det før), hvis der ikke er andre der har samlet den op inden.
Avatar billede iver_mo Nybegynder
13. april 2011 - 19:52 #12
Så prøver vi en sidste gang:


SoundMixer.stopAll();
var music_on:Number = 0;
var temp_id:Number = 0;
var mySound:Sound = new Sound();
var songURL:URLRequest = new URLRequest("Dreaming.mp3");
var channel1:SoundChannel = new SoundChannel();
var resumeTime:Number = 0;
mySound.load(songURL);
play_btn.addEventListener(MouseEvent.CLICK, playSound);
pause_btn.addEventListener(MouseEvent.CLICK, pauseSound);
stop_btn.addEventListener(MouseEvent.CLICK, stopSound);

function playSound(e:MouseEvent):void {
    if ((music_on == 0) || (temp_id != 1)) {
        channel2.stop();
        channel3.stop();
        channel4.stop();
        channel1 = mySound.play(resumeTime);
        music_on = 1;
        temp_id = 1;
    }
}

function pauseSound(e:MouseEvent):void {
    resumeTime = channel1.position;
    channel1.stop();
    music_on = 0;
    temp_id = 0;
}

function stopSound(e:MouseEvent):void {
    channel1.stop();
    resumeTime = 0;
    music_on = 0;
    temp_id = 0;
}

var mySound2:Sound = new Sound();
var songURL2:URLRequest = new URLRequest("WingsOfAnEagle.mp3");
var channel2:SoundChannel = new SoundChannel();
var resumeTime2:Number = 0;
mySound2.load(songURL2);
play_btn2.addEventListener(MouseEvent.CLICK, playSound2);
pause_btn2.addEventListener(MouseEvent.CLICK, pauseSound2);
stop_btn2.addEventListener(MouseEvent.CLICK, stopSound2);

function playSound2(e:MouseEvent):void {
    if ((music_on == 0) || (temp_id != 2)) {
        channel1.stop();
        channel3.stop();
        channel4.stop();
        channel2 = mySound2.play(resumeTime2);
        music_on = 1;
        temp_id = 2;
    }
}

function pauseSound2(e:MouseEvent):void {
    resumeTime2 = channel2.position;
    channel2.stop();
    music_on = 0;
    temp_id = 0;
}

function stopSound2(e:MouseEvent):void {
    channel2.stop();
    resumeTime2 = 0;
    music_on = 0;
    temp_id = 0;
}

var mySound3:Sound = new Sound();
var songURL3:URLRequest = new URLRequest("FragilenYoung.mp3");
var channel3:SoundChannel = new SoundChannel();
var resumeTime3:Number = 0;
mySound3.load(songURL3);
play_btn3.addEventListener(MouseEvent.CLICK, playSound3);
pause_btn3.addEventListener(MouseEvent.CLICK, pauseSound3);
stop_btn3.addEventListener(MouseEvent.CLICK, stopSound3);

function playSound3(e:MouseEvent):void {
    if ((music_on == 0) || (temp_id != 3)) {
        channel1.stop();
        channel2.stop();
        channel4.stop();
        channel3 = mySound3.play(resumeTime3);
        music_on = 1;
        temp_id = 3;
    }
}

function pauseSound3(e:MouseEvent):void {
    resumeTime3 = channel3.position;
    channel3.stop();
    music_on = 0;
    temp_id = 0;
}

function stopSound3(e:MouseEvent):void {
    channel3.stop();
    resumeTime3 = 0;
    music_on = 0;
    temp_id = 0;
}


var mySound4:Sound = new Sound();
var songURL4:URLRequest = new URLRequest("InLove.mp3");
var channel4:SoundChannel = new SoundChannel();
var resumeTime4:Number = 0;
mySound4.load(songURL4);
play_btn4.addEventListener(MouseEvent.CLICK, playSound4);
pause_btn4.addEventListener(MouseEvent.CLICK, pauseSound4);
stop_btn4.addEventListener(MouseEvent.CLICK, stopSound4);


function playSound4(e:MouseEvent):void {
    if ((music_on == 0) || (temp_id != 4)) {
        channel1.stop();
        channel2.stop();
        channel3.stop();
        channel4 = mySound4.play(resumeTime4);
        music_on = 1;
        temp_id = 4;
    }
}

function pauseSound4(e:MouseEvent):void {
    resumeTime4 = channel4.position;
    channel4.stop();
    music_on = 0;
    temp_id = 0;
}

function stopSound4(e:MouseEvent):void {
    channel4.stop();
    resumeTime4 = 0;
    music_on = 0;
    temp_id = 0;
}


buy_btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage_2);

function fl_ClickToGoToWebPage_2(event:MouseEvent):void
{
    navigateToURL(new URLRequest("http://www.gdc.dk/ (...)), "_blank");
}
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
IT-kurser om Microsoft 365, sikkerhed, personlig vækst, udvikling, digital markedsføring, grafisk design, SAP og forretningsanalyse.

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester