PDA

View Full Version : adding a sound to drag n drop


ub_flash
11-12-2002, 10:04 PM
hi people :)

i'm creating a simple puzzle with drag n' drop actions, and i want to add a sound to the if statement so that when the user drops the letter on the target it activates the sound (applause) as well.

here's the cript for the d&d:

on (press) {
startDrag (this, true);
}
on (release) {
stopDrag ();
if (this._droptarget == "/box1") {
_root.box1.gotoAndStop(2);
}
}

any help is much appreciated,

ub

Esquared
11-13-2002, 12:09 AM
To call sounds with actionscript you need to create a sound object. One note on these: I recommended that you create an empty movie clip called, for instance, Sounds, on the _root level to contain any/all sounds you want to play with AS. Also, any sounds you want to use in this manner must be exported for actionscript - just CTRLclick on the sound file in the library and select linkage. That said, here's the code to place on the Sounds mc:

onClipEvent(load)
{
Sound1 = new Sound(); //Sound1 being whatever you want (drop, applause, etc.)
Sound1.attachSound("Sound1") //The quotes being whatever you named it in the linkage

//repeat for as many sounds as you want
}

That's all you need to do to create the sound objects. As for playing them:

_root.Sounds.Sound1.start()

You can also add parameters to the start call for offset in seconds before the sound plays and the number of times it loops, in that order, but these don't seem necessary in your case.

Hope you get it worked out!

jezza_Lee
10-10-2005, 08:35 AM
To call sounds with actionscript you need to create a sound object. One note on these: I recommended that you create an empty movie clip called, for instance, Sounds, on the _root level to contain any/all sounds you want to play with AS. Also, any sounds you want to use in this manner must be exported for actionscript - just CTRLclick on the sound file in the library and select linkage. That said, here's the code to place on the Sounds mc:

onClipEvent(load)
{
Sound1 = new Sound(); //Sound1 being whatever you want (drop, applause, etc.)
Sound1.attachSound("Sound1") //The quotes being whatever you named it in the linkage

//repeat for as many sounds as you want
}

That's all you need to do to create the sound objects. As for playing them:

_root.Sounds.Sound1.start()

You can also add parameters to the start call for offset in seconds before the sound plays and the number of times it loops, in that order, but these don't seem necessary in your case.

Hope you get it worked out!

Im stuck in drag and drop with sounds too at the memont and have tried creating a sound movie clip with the code you mentiones as above, however there's an error which says "Clip events are permitted only for movie clip instances onClipEvent(load)" Isn't it already a movie clip? Please feel free to help

oldnewbie
10-10-2005, 01:02 PM
Answered your other thread.

jezza_Lee
10-11-2005, 11:55 AM
thanx