lundi 13 février 2017

Overlapping sounds Actionscript 3/AIR

I have a Play(Resume)/Pause button in Frame 1 (Home Page). However, when the user navigates the application and decides to go back in Home Page by pressing the home button, the sound overlaps. And when the user press the other buttons, it began to overlap endlessly. Thanks! This is an Actionscript 3 Flash Application to be deployed in Android device using Adobe AIR. Here is my code:

import flash.net.URLRequest;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.ui.Mouse;
import flash.events.MouseEvent;

var played:Boolean = false;
var soundFile:URLRequest = new URLRequest("music.mp3");
var mySound:Sound = new Sound;

if(played== false){
            played= true;
mySound.load(soundFile);
var myChannel:SoundChannel = new SoundChannel;
myChannel = mySound.play(0,999);

pause_btn.addEventListener(MouseEvent.CLICK,pauseSound)
function pauseSound(event:MouseEvent):void 
    {
        var position = myChannel.position;
        myChannel.stop();
        play_btn.addEventListener(MouseEvent.CLICK,resumeSound);
        }

function resumeSound(event:MouseEvent):void
    {
        myChannel = mySound.play(myChannel.position);
    }
}

Aucun commentaire:

Enregistrer un commentaire