0
votes

I'd appreciate seeing some examples of ActionScript 3.0 code that deploys any kind of sound files to be used in Flash Pro files, for final output as SWF.

I am using the code (below) for the Base class of a Bubble Game (of sorts), and the problem is, that when popped, the sound plays a little too late, not spot on.

thanks. This is my code - which is linked to the Bubbles in the library of my FLA:

package 
{
    import flash.display.*;
    import flash.events.*;
    import flash.media.Sound;
    import flash.net.URLRequest;

    public class BubbleBaseNew4 extends MovieClip
    {
        var thisBubble:MovieClip;
        var navdock:MovieClip;
        var thisParent:*;
        private var snd:Sound = new Sound();

        public function BubbleBaseNew4()
        {
            this.addEventListener(Event.ADDED_TO_STAGE, initialize);//off http://kb2.adobe.com/cps/838/cpsid_83815.html to do ADDED_TO_STAGE instead of ADDED
            this.addEventListener(MouseEvent.CLICK, pop);
        }

        function initialize(event:Event):void
        {
            this.removeEventListener(Event.ADDED_TO_STAGE, initialize);//this causes sym_mc to be defined as an Ojbect

            thisParent = event.currentTarget.parent;
            navdock = thisParent.nav_mc;
            thisBubble = MovieClip(this.parent.getChildByName(this.name));

            this.addEventListener(Event.ENTER_FRAME, moveBubble);

            var req:URLRequest = new URLRequest("my_own_twp_noise_tremolo_phaser_.mp3");
            snd.load(req); 
        }

        function moveBubble(event:Event):void
        {
            if(navdock != null && this.hitTestObject(navdock)) 
            {
                trace("HIT!");
                this.removeEventListener(Event.ENTER_FRAME, moveBubble);
                this.removeEventListener(MouseEvent.CLICK, pop);
                this.parent.addChild(this);//this adds the bubble that's removed, i think.
                this.parent.removeChild(thisBubble);
            }
            else
            {
                var mc:MovieClip = event.target as MovieClip;
                if(currentFrame == 1)
                {
                    mc.x = Math.random() * stage.stageWidth;
                    mc.y = Math.random() * stage.stageHeight;

                    rotation += Math.random() * -90;
                }

            }
        }

        function pop(event:MouseEvent):void
        {
            /*var bzp:Sound = Sound(thisParent.my_own_twp_noise_tremolo_phaser_.wav);
            this.load(bzp);*/
            this.removeEventListener(Event.ADDED_TO_STAGE, initialize);
            this.removeEventListener(MouseEvent.CLICK, pop);
            this.removeEventListener(Event.ENTER_FRAME, moveBubble);

            var main:MovieClip = MovieClip(this.parent.parent);
            main.increaseScore();
            //mediary 'increaseScore function' variable
            var main4:MovieClip = MovieClip(this.parent.parent);
            main4.increaseScore4();
            this.parent.removeChild(thisBubble);
            snd.play();
        }
    }
}
1

1 Answers

0
votes

Two things you could try. The first is to change the mouseEventListener for the pop function from MouseEvent.CLICK to MouseEvent.MOUSE_DOWN, that way you don't have to wait for a MOUSE_UP before the function is called.

The second thing is to make sure the sound file is trimmed down so there is absolutely not one nanosecond of silence at the beginning. Audacity is a good program to use for stuff like that.