-
attachSound doesn't play
I have a routine to play clicks etc, which uses attachSound to play the sounds. If I run this via the authoring mode, the sounds play fine.
If, however, I make this a separate SWF, then load it and call "playClick.byName(sndName)", then nothing plays.
What's wrong?
Frame 1 of playClick.fla --
Code:
var soundsList:Array =
["clack", 1.0,
"cli-clunk", 0.6,
"click-muffled", 1.0,
"click-soft", 1.0,
"click", 1.0,
"clurk", 1.0,
"ddengf", 0.7,
"ddink-tiny", 1.5,
"ddinkle", 0.7,
"dumpf", 1.0,
"ka-click", 1.0,
"kclick-tiny", 1.0,
"tappf", 1.0,
"tchink", 1.0,
"tenk", 0.6,
"whink", 0.5,
"zzerrn", 0.7]
clickSound = new Sound();
var i:Number = 0;
// Entry point to play short "click" (etc) sounds
function byName(sndName:String):Boolean {
sndName = sndName.toLowerCase();
trace("playClick: " + sndName);
for ( i = 0; i<soundsList.length; i+= 2 ) {
if ( sndName == soundsList[i].toLowerCase() ) {
playIt(sndName, soundsList[i+1]);
return true;
}
}
// If here, requested sound not found
return false;
}
function playIt(sndName, sndVol) {
clickSound.stop();
clickSound.attachSound(sndName); // attach a sound
clickSound.setVolume(sndVol * 100);
clickSound.start();
}
-
Can't Re-Member
If you are loading this as an external swf, and making the call from your main timeline (_level0 / _root), your call would look something like :
Code:
// if you are loading into a container clip w/instance name is 'mt_clip'...
mt_clip.byName(sndName);
// if loading into a _level.. let's say 4...
_level4.byName(sndName);
[ EDIT ]
on second thought.. you probably have to target the sounds properly as well.... more like :
Code:
// if you are loading into a container clip w/instance name is 'mt_clip'...
mt_clip.byName(mt_clip.sndName);
// if loading into a _level.. let's say 4...
_level4.byName(_level4.sndName);
-
Madzigian, thanks, but I don't understand.
The movieClip swf is "playClick.swf" loaded into the container "playClick". Using trace shows that the routines in "playClick" ARE being called correctly.
"sndName" is just a string, i.e. "click" which matches the linkageID inside the playClick.swf
Everything works fine, just no sound plays.
You mention "_level4" as an example; why should I have to specify the level? I have other routines that play streaming sounds via the internet. The only differnce I can see here is the "attachSound" method...
-
Can't Re-Member
my mention of _level4 was because i didn't know if you were loading into a _level or an empty clip... now i understand, it's an empty clip.
why it doesn't work seems odd... can you post the code you're using to call the function? (not just playClick.byName(sndName), but an actual usage of it) or even better, post the FLA's so i can have a look at them?... It's gotta be something simple that's just being overlooked. because from what i can see, your coding looks perfect.
-
I just found the solution !!!!
http://developer.mabwebdesign.com/blog/?p=38
Stupidly, you have to use --
Code:
clickSound = new Sound(this); // Note "this" as arg!!!
That's the ONLY "new sound" I declare, and it's set up at load-time. (Doesn't have to be set up for each "click" that I play)
This seems very strange to me, that the attachSound is level-dependent in this way. What a mess!
Everything works now.
-
Can't Re-Member
lol.. see i figured it had to be something simple like that. Glad you figured it out.
Great little script by the way!!
-
Originally Posted by madzigian
lol.. see i figured it had to be something simple like that. Glad you figured it out.
Great little script by the way!!
Thanks. The whole script includes an "interactive sampler" which I can bring on-screen anytime and then click around to hear all the sounds and see their names, in case I forget what they're called.
BTW- additional reference - see comments by
"Skewalski said on Jan 14, 2005 at 4:08 AM :"
-- on page 00001672.html of the Macromedia/Adobe "LiveDocs"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|