The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 4 of 4

Thread: Controlling sounds with actionscript issues

  1. #1

    Controlling sounds with actionscript issues

    Hello

    Whenever I stop a sound with actionscript it stops all the sounds (that are also being controlled with actionscript). Also, whenever I change the volume of one sound with actionscript it changes the volume of all sounds.

    I have my space ship movie clip and when you hold down the left mouse button it makes the ship spin it's blade and it also starts the blade moving sound. In my game I am going to have spinning the blade use more fuel, so you want to stop spinning the blade as soon as possible. When I release the mouse the ship blade stops moving and the blade sound stops too (like it should). BUT all the other sounds - such as the sound of a dying enemy, stop too.

    Here's the swf

    Any help is MUCH appreciated...

    Here is all the code on my space ship mc

    Code:
    onClipEvent(load)
    {
        speed = 2;
        bladeSpeed = 9;
        bladeSpinning = false;
    }
    
    onClipEvent(enterFrame)
    {
        var zombieArray:Array = new Array(_root.zombie1, _root.zombie2, _root.zombie3, _root.zombie4, _root.zombie5);
        for (var k = 0; k < zombieArray.length; k++)
        {
            distance = Math.sqrt(((zombieArray[k]._x - this._x)*(zombieArray[k]._x - this._x))+((zombieArray[k]._y - this._y)*(zombieArray[k]._y - this._y)));
            if(distance < (this._width / 2))
            {
                if(bladeSpinning == true)
                {
                    if (zombieArray[k].dead == true)
                    {
                    } else
                    {
                        zombieArray[k].gotoAndPlay(2);
                        zombieArray[k].dead = true;
                        screamPick = random(3);
                        if (screamPick == 0)
                        {
                            scream = new Sound();
                            scream.attachSound("scream2")
                            scream.start();
                        }
                        if (screamPick == 1)
                        {
                            scream = new Sound();
                            scream.attachSound("scream4")
                            scream.start();
                        }
                        if (screamPick == 2)
                        {
                            scream = new Sound();
                            scream.attachSound("scream5")
                            scream.start();
                        }
                    }
                }
            }
        }
        
        mouseDistanceX = (_root._xmouse - this._x);
        if (mouseDistanceX < 0)
        {
            mouseDistanceX *= -1;
        }
        if (mouseDistanceX < 2)
        {
        } else
        {
        
            angle = Math.atan2 (_root._xmouse - this._x, _root._ymouse - this._y);
            this._x += speed * Math.sin (angle);
            this._y += speed * Math.cos (angle);
        }
    
        
        if(bladeSpinning == true)
        {
            this.blade._rotation += bladeSpeed;
        } else
        {
        }
    }
    onClipEvent(mouseDown)
    {
        bladeSpinning = true;
        SawSound = new Sound ();
        SawSound.attachSound("saw");
        SawSound.start();
    }
    onClipEvent(mouseUp)
    {
        bladeSpinning = false;
        SawSound.stop();
    }

  2. #2
    sounds are attached to a timeline

    when you you alter volume you volume you alter the sound of all sounds in that time line

    Code:
    scream = new Sound();
                            scream.attachSound("scream2")
                            scream.start();
    the brackets after new Sound () is where you specify the time line if you leave them empty they default to the main (root) time line

    new Sound(this where you state the time line);

    as you have not specified they are all in the same time line and you control th volume of all at one time

    i personally put them into their own timeline using empty movie clips

    Code:
    var empty:MovieClip = this.createEmptyMovieClip("empty1", this.getNextHighestDepth());
    var scream:Sound = new Sound(empty1);
    scream.attachSound("scream2");
    scream.start();
    hope this helps


    and then i can control sounds separately

    hope this helps
    Last edited by neilmmm; May 29th, 2008 at 07:47 PM.

  3. #3
    Thank you! That was a very informative and helpful post. It solved all my sound issues!

  4. #4
    yw

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012