Here’s a Handy little tip I just figured out today. So I have a button that plays sound and once if finishes playing it should fire the Event.SOUND_COMPLETE. In this events handler, it resets the position back to the beginning of the clip. Now the problem is once I try to play it again, it doesn’t seem to fire the Event.SOUND_COMPLETE event. Have you ever had the issue of your Event.SOUND_COMPLETE not firing properly?? Read on and find out why……
After some debugging, I noticed that every time you pause a sound and play it again, a new SoundChannel is returned. Any event listeners I had applied to the SoundChannel before are disregarded once I pause and play. Instead of :
function playSound():void
{
mySound : Sound = new Sound();
mySound.addEventListener(Event.COMPLETE, soundLoaded);
mySound.load(MY SONG REQUEST);
}
function soundLoaded(e : Event):void
{
myChannel = new SoundChannel();
myChannel.addEventListener(Event.SOUND_COMPLETE, soundComplete);
myChannel = mySound.play();
}
function soundComplete(e : Event):void
{
position = 0;
playChannel()
pauseChannel();
myChannel.addEventListener(Event.SOUND_COMPLETE, soundComplete);
}
function pauseChannel():void
{
myChannel.stop();
position = myChannel.position;
}
function playChannel():void
{
myChannel = mySound.play(position);
}
But It should be :
function playSound():void
{
mySound : Sound = new Sound();
mySound.addEventListener(Event.COMPLETE, soundLoaded);
mySound.load(MY SONG REQUEST);
}
function soundLoaded(e : Event):void
{
myChannel = new SoundChannel();
myChannel.addEventListener(Event.SOUND_COMPLETE, soundComplete);
myChannel = mySound.play();
}
function soundComplete(e : Event):void
{
position = 0;
playChannel();
pauseChannel();
}
function pauseChannel():void
{
myChannel.stop();
position = myChannel.position;
}
function playChannel():void
{
myChannel = mySound.play(position);
myChannel.addEventListener(Event.SOUND_COMPLETE, soundComplete);
}
You need to register the event listener again once you call play. I hope this saves 30 minutes of your day once you start screaming…WHERE’S MY SOUND!!!
- Flash, CSS, AS3
- Created @radical.media for Tommy Hilfiger
- Jr. Flash Developer - Create the page Template
- Made use of a Tweening Engine
ul>
- Flash, CSS, AS3
- Created @radical.media for Tommy Hilfiger
- Jr. Flash Developer - Create the page Template
- Made use of a Tweening Engine
- Flash, XML, AS3
- Created at Marvel Entertainment
- Jr. Flash Developer - Translate AS2 to AS3
- Made use of a Tweening Engine
- Receive XML and send Requests via PHP
- Flash, CSS, AS3
- Created @radical.media for Tommy Hilfiger
- Jr. Flash Developer - Create the page Template
- Made use of a Tweening Engine
- Flash, CSS, AS3
- Created @radical.media for Viacom
- Jr. Flash Developer - Help style the CSS, animated logo, and minor AS3/AS2 Flash work
- Wordpress, PHP, XHTML, CSS
- Programmed this design (by BetterInPink) for Wordpress 2.7.1. This features a custom sidebar using CSS Layers and a custom switching option for unique header on pages
Hey Flashers, I know its been a long time since the last tip. Time has not been on my side recently, but I’m getting some more free time and I’ll be posting regularly again. Be on the look out, I have some new websites and articles coming out. You can see the latest website to date, Galley Smith Blog. But aside from all of that, down to the tip.
I’m currently working on a 3D Flash site and I decided to use Flash 10 3D instead of Papervision3D. I felt it would be overkill to use Papervision for this project since we couldn’t get our animated 3d models into Papervision successfully. As everyone knows or some who don’t, FP10 ‘s z sorting is non-existent. I needed to have floating panels zoom up to show maximized version of the panel. The problem is that, scaling them up, if it is not at the top of the DisplayList, it would show the other panels in front of it still.
I needed to make a function that would always keep my selected panel above the rest. The kreativeSort function was born. Its still in its infancy, but I see potential in it. I will work on it more throughout the project at keep everyone up to date with the progress. Here is the commented function for everyone to use if you happen to have the same issue.
I’ve been steered in a better direction and found of an alternative and faster way of doing this over at Actionscript.org from lordofduct. Check out the updated function at the bottom.
/**
* Puts selected DisplayObject on top of other DisplayObects in its container
*
* @param parent Container DisplayObject that holds our children.
* @param panel Child we want to be displayed on top of the rest
*
* @author Clemente Gomez - kreativeKING
*/
private function kreativeSort(parent:DisplayObjectContainer, panel:DisplayObject) : void
{
var i : int = 0;
var length : Number = parent.numChildren;
//Position the child is located at.
var pos:int;
for (i ; i < length ; i++)
{
// When child matches the level we are at in the container, recored the level in variable "pos".
if(parent.getChildAt(i) == panel)
{
pos = i;
break;
}
}
// Removes child out of container.
parent.removeChildAt(pos);
//Adds the child back on top of the rest.
parent.addChildAt(panel, parent.numChildren);
}
function kreativeSort( parent:DisplayObjectContainer, panel:DisplayObject ):void
{
if (parent.contains( panel )) parent.addChild( panel );
}
- Wordpress, PHP, XHTML, CSS
- Programmed this design (by BetterInPink) for Wordpress 2.8. This features a custom Twitter Feed on the sidebar and various depths using CSS Layers. Also a custom Theme Options panel for changing the options easily.
Hey people, I’ve been published again in Web Designer Magazine Issue 159. In this tutorial, I walk you through how to make a MP3 player with a sound visualizer. Its a pretty short and straight to the point tutorial. Hopefully everyone will be able to follow along and make some cool mp3 players. If there are any concerns or questions, post it here on the blog and I’ll get back to you ASAP.
Go pick up your copy and leave some feed back. Check out a preview here