PDA

View Full Version : Trigger Sound Object from Custom Function


TheMonkxx
03-03-2006, 11:59 PM
Hello,

I have a movie that is creating a sound object and loading the sound into it. Now a script on in a sepetate MC calls the function and passes it parameters that it needs to call the sound in question. Trouble is when the function gets the parameters it won't play the sound. But if I hand code the same parameters into the function the sound plays fine. Have a looK:

------------------------------------------------
trexstep=new Sound();
trexstep.attachSound("sound_trexstep");

function playsounds(soundname,looped) {
_root.soundname.start(0,looped);
//_root.trexstep.start(0,1)
}
-----------------------------------------------

And here is the code that appears which calls the function:

-----------------------------------------------
_root.playsounds("trexstep",1);
-----------------------------------------------

The function call works correctly because if I uncomment the code on the second line of my function I hear the sound. For some reason I can't play the sound when I pass the values to the function. Any ideas? (I did a trace on the function and it's receiving the values the function call is giving it)

Thanks!
Monk

Note: I realise I could save myself the trouble and just add "_root.trexstep.start(0,1)" to the frame but when I noticed this wasn't working I became obsessed on figuring out why. heh. You can't learn if you never take the time to figure out "why?" ;)

oldnewbie
03-04-2006, 12:03 AM
Have you tried it without the double quotes?

_root.playsounds(trexstep,1);

TheMonkxx
03-04-2006, 01:14 AM
Hi oldnewbie,

When I tried taking off the quotes the varaible and traced the variable in the fiunction it resolved to "undefined".

Any ideas?
Monk

:)

oldnewbie
03-04-2006, 01:39 AM
Can you attach your .fla or a mockup one replicating the problem?

sophistikat
03-04-2006, 02:36 AM
does this help?function playsounds(soundname,looped) {
_root[soundname].start(0, looped);
//_root.trexstep.start(0,1)
}

TheMonkxx
03-04-2006, 03:18 AM
That worked. Interesting.. So what does putting the parameter name in brackets do? How is it different than the . format?

It's the first time I've seen something like that and I'd like to understand how it works!

Thanks guys!

TheMonkxx
03-04-2006, 04:16 AM
NM I found my own answer here! heh.
http://www.actionscript.org/tutorials/intermediate/advanced_pathing/index.shtml

Monk

sophistikat
03-04-2006, 06:07 PM
thanks for that link; people always ask me that question and now i can just pass on this link instead of writing it again, thanks.