Skip to main content
edwinmerced
Inspiring
September 11, 2011
Question

Sound position and length on Slider Component AS3

  • September 11, 2011
  • 1 reply
  • 3239 views

Hello:


I have the following working great:

stop_btn.setStyle("icon", square_mc);
player_btn.setStyle("icon", next_mc);

import flash.events.Event
import flash.events.MouseEvent;
import flash.media.SoundTransform;

var alreadyDefined:Boolean;
volumen.value = 1;

if(!alreadyDefined){

alreadyDefined=true;

var isPlaying:Boolean = new Boolean();
var pausePosition:Number = new Number();


var soundClip:Sound = new Sound();
var sndChannel:SoundChannel;


soundClip.load(new URLRequest("audio/music.mp3"));
soundClip.addEventListener(Event.COMPLETE, onComplete, false, 0, true);


player_btn.addEventListener(MouseEvent.MOUSE_DOWN, btnPressController, false, 0, true);
stop_btn.addEventListener(MouseEvent.MOUSE_DOWN, btnPressStop, false, 0, true);

function onComplete(evt:Event):void {
    sndChannel = soundClip.play();
    isPlaying = true;

}

function btnPressController(evt:MouseEvent):void
{
    switch(isPlaying)
    {
        case true:
            //controller.text ="Sound Paused";
            player_btn.setStyle("icon", pause_mc);
            pausePosition = sndChannel.position;
            sndChannel.stop();
            isPlaying = false;
        break;
        case false:
            //controller.text ="Sound Playing";
            player_btn.setStyle("icon", next_mc);
            sndChannel = soundClip.play(pausePosition);
            isPlaying = true;
        break;
    }
}

function btnPressStop(evt:MouseEvent):void
{
    pausePosition = 0;
    sndChannel.stop();
    //controller.text ="Play Sound";
    player_btn.setStyle("icon", next_mc);
    isPlaying = false;
}


}

volumen.addEventListener(Event.CHANGE, sliderChanged);

function sliderChanged(evt:Event):void {

var vol:Number = volumen.value;
volumen.liveDragging = true;


var st:SoundTransform = new SoundTransform(vol);
if(sndChannel != null){
    sndChannel.soundTransform = st;
}
}


exit_btn.addEventListener(MouseEvent.CLICK, fexit);

function fexit(event:MouseEvent):void{
    SoundMixer.stopAll(); 
    Loader(this.parent).unloadAndStop();
}

I have another slider component on the movie with instance name PROGRESO


I would like for PROGRESOnto indicate (update) the sounds progress as it plays and be able to scrub through the sound.


Any idea how I can achieve this? Thanks for any help

This topic has been closed for replies.

1 reply

Inspiring
September 11, 2011

You can read SoundChannel.position with a timer:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/SoundChannel.html#position

edwinmerced
Inspiring
September 11, 2011
so something like this?

var myTimer:Timer = new Timer(1000, 1); myTimer.addEventListener(TimerEvent.TIMER, runTimer); myTimer.start(); function runTimer(event:TimerEvent):void { progreso.position = SoundChannel.value; }

But not working.

By the way, you can take a look here: http://jejedesigns.com/jejedesignsaudioplayer/audio.swf

Att.,

Thanks for any help

Edwin

Inspiring
September 11, 2011

1. There is no parameter value on SoundChannel

2. There are no static properties on the SoundChannel - you need to use instance of it - not class

3. your Timer runs only once. You need a Timer that runs while sound is playing. So - remove second parameter in Timer instance.