Flash, random sound
- Started
- Last post
- 10 Responses
- ganon
i am using the attachSound method to bring audio clips into flash...i then push the sound object names to an array, and am trying to play a random one...everything is fine, i get a random sound but i cant get it to play, whats wrong here...:
//random sound function, array
randomSound(correctSound_array);//random sound function
function randomSound(arry) {
var ranNum = Math.floor(Math.random() * arry.length);
var ranSound = arry[ranNum];
trace (ranSound + " ranSound");
ranSound.start (0, 10);
}
- jkosoy0
What happens when you trace ranSound out? What does it output?
What if you simply return ranSound and then call it from outside the function?
- jkosoy0
What happens when you trace ranSound out? What does it output?
What if you simply return ranSound and then call it from outside the function?
- ozhanlion0
trace() is yer friend.
where is your array btw?
- ganon0
the trace does produce a random sound objects name, as i had hoped...its this line,
ranSound.start (0, 10);
which just wont play the audio...i did try this too, using an a function just to get a random array item #...:
//play random correct sound from array
this.correctSound_array[randomLe... (0, 10);no go either....
- ganon0
all code, arrays, are in one frame at the _root of the fla....
- unfittoprint0
you should specify the range of the Sound Object when initiating it:
mySound = new Sound(this);
and if they are originated from an external library you may have some problems....
- ganon0
unfit here is an example of what i am pushing to the array...:
//array
this.correctSound_array = new Array();//correct one
this.createEmptyMovieClip("corre... 20);
this.correct01 = new Sound(correct01_mc);
this.correct01.attachSound("corr...
this.correct01.setVolume(100);
this.correct01.setPan(0);
this.correctSound_array.push("co...erverything works ok, except for the start line in the function(prev post)....
- unfittoprint0
check: correct instance name
//test purposes
do it all on the _roottry changing this line:
this.correct01 = new Sound(correct01_mc)to
this.correct01_mc.mcSound = new Sound(this)
or
this.correct01_mc.mcSound= new Sound(this.correct01_mc)
- ganon0
no luck with that unfit, it must be something else...because when i have
this.correct01.start (0, 10);
the sound plays as it should...my functions "ranSound" gets "correct01" (prev post), however fails to play it with...:
ranSound.start (0, 10);
- ganon0
FYI, i got it...in the function, this does not work...:
ranSound.start (0, 2);
however, this does...:
this[ranSound].start (0, 2);