Skip to main content
Participating Frequently
April 1, 2008
Question

audio player script help

  • April 1, 2008
  • 6 replies
  • 435 views
I have constructed a mini audio player with the help of a tutorial, action script 3 (code provided below) and flash cs3.

I'm fairly new to Flash and just am curious what I need to add and what's missing...Q. I want this play/stop button to only place the audio file once and then stop. Right now the audio file just loops over and over until the stop button is clicked. Other than this the produced swf works great... just don't want it to loop. So, what am I missing in my script?

action script
========================================
This topic has been closed for replies.

6 replies

Participating Frequently
July 16, 2008
See this cool mp3 xml player with visualization, playlist and skins. Fully customisable. Vector. http://flashden.net/item/mp3-xml-strongplayerstrong-with-visualization-and-skins-vectorised/11851
Participating Frequently
April 6, 2008
never mind i figured it out. i had it set to play 5 times over instead of once

channel = sound.play(0,5);

changed it to

channel = sound.play(0,1);

like i said im still learning. thanks for all the help though!
Participating Frequently
April 6, 2008
no luck :(
Inspiring
April 5, 2008
Have you tried to drop the "private" attribute from the function definition? That would be my first guess...

Peter H.
Participating Frequently
April 4, 2008
i tried what you have there....i plugged it all in and am getting and error.

1013: The private attribute may be used only on class property definitions.

For the record. I was following a tutorial on how to assemble this so that's probably why some object names may seem worrisome.

So, any ideas?
Participating Frequently
April 3, 2008
any help?
Inspiring
April 3, 2008
I'm fairly new to AS3 but I have some code that is working for me.

I think you need to add an event listener to your startPlay function:

function startPlay(event:MouseEvent):void {
playBtn.visible = false;
stopBtn.visible = true;
channel = sound.play(0,5);
channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete, false, 0, true);
}

then add a function to call when the sound has played completely:

private function onPlaybackComplete(evt:Event):void {
channel.stop();
channel.removeEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
}


I've not tested this specific combination of code, I just pulled parts from some code I have that is working. But this should work.

I am also a little uncomfortable with your object names. I'm afraid the might be too close to a reserved word. I only say this because that bit me last week when I was first working on this.

In any case, I hope this helps. :-)

Peter H.