View Full Version : setVolume problem
charlie_su1986
February 21st, 2004, 11:30 PM
Hi all
usually i can find the solutions of the problems i have in this great forum.....but this time....i guess i really need to ask :sigh:
okay, i have a flash document that contains two wav file in the library with ID name "soundloop1" and "soundloop2". and there is no other stuff except for the following code on the first frame:
_root.mySound1 = new Sound(mc1);
_root.mySound1.attachSound("soundloop1");
_root.mySound1.start(0, 50);
_root.mySound2 = new Sound(mc2);
_root.mySound2.attachSound("soundloop2");
_root.mySound2.start(0, 50);
_root.mySound1.setVolume(20)
_root.mySound2.setVolume(100)
trace(_root.mySound1.getVolume())
how come the output is 100(and it sounds like 100 too...pretty loud :sigh: ) ?? what did i do wrong?
thanx in advance
claudio
February 22nd, 2004, 02:34 AM
Your code should work. :-/
charlie_su1986
February 22nd, 2004, 03:48 AM
claudio:
did it work on yours??:puzzle:
i'm running flash 2004
claudio
February 22nd, 2004, 03:52 AM
I havent tried but it should work on MX, not sure about MX2004 though.
Voetsjoeba
February 22nd, 2004, 06:14 AM
It should work indeed :-/ This happens when no target is specified for a Sound object, but this is the case, so I can't see anything wrong with it. Can you post your FLA so we can have a look ?
charlie_su1986
February 22nd, 2004, 07:08 AM
here is the attachment. Thanks everyone :)
http://members.shaw.ca/charlie_su1986b/setvolume_test.fla
Voetsjoeba
February 22nd, 2004, 07:27 AM
This looks a lot like Sound objects with no target. When you set the volume of one of them, they all change. And indeed - mc1 and mc2 don't exist ! Look at this:
_root.mySound1 = new Sound(mc1);
_root.mySound1.attachSound("soundloop1");
_root.mySound1.start(0, 50);
//
_root.mySound2 = new Sound(mc2);
_root.mySound2.attachSound("soundloop2");
_root.mySound2.start(0, 50);
//
_root.mySound1.setVolume(20);
trace(_root.mySound1.getVolume());
trace(_root.mySound2.getVolume());
//20
//20
// Changing the volume of a sound object without target is changing the volumer of all sound objects in the movie.
Because mc1 and mc2 simply don't exist, they're not valid targets. If you create a Controlling sound object without target is the same as controlling every sound object in the movie. From the AS Dictionary (http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary654.html):
The Sound object lets you control sound in a movie. You can add sounds to a movie clip from the Library while the movie is playing and control those sounds. If you do not specify a target when you create a new Sound object, you can use the methods to control sound for the whole movie. You must use the constructor new Sound to create an instance of the Sound object before calling the methods of the Sound object.
So to fix this:
this.createEmptyMovieClip("mc1",1);
this.createEmptyMovieClip("mc2",2);
_root.mySound1 = new Sound(mc1);
_root.mySound1.attachSound("soundloop1");
_root.mySound1.start(0, 50);
//
_root.mySound2 = new Sound(mc2);
_root.mySound2.attachSound("soundloop2");
_root.mySound2.start(0, 50);
//
_root.mySound1.setVolume(20);
trace(_root.mySound1.getVolume());
trace(_root.mySound2.getVolume());
//20
//100
:)
charlie_su1986
February 22nd, 2004, 11:51 AM
ahh thanx a lot, that worked :D
Voetsjoeba
February 22nd, 2004, 12:29 PM
Anytime ;)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.