|
-
[CS3] AS2: Playing a sound n00b :)
Hi folks,
I want to have something play a sound when it is clicked, however, its a movieclip not a button. my code so far looks like this:
onClipEvent (enterFrame) {
myRadians = Math.atan2(_root._ymouse-this._y, _root._xmouse-this._x);
// myDegrees = Math.round((myRadians*180/Math.PI));
_root.yChange = Math.round(_root._ymouse-this._y);
_root.xChange = Math.round(_root._xmouse-this._x);
_root.yMove = Math.round(_root.yChange/1);
_root.xMove = Math.round(_root.xChange/1);
this._y += _root.yMove;
this._x += _root.xMove;
this._rotation = myDegrees+90;
}
when the left mouse button is released i want a gunshot sound to play can i achieve this?
would look something like this?
on (release) {
play("GUNSHOT_.WAV");
Any thoughts, thanks?
-
Media Developer
If this sound is being loaded from your library, then it needs to look like this:
Code:
on (release){
var gunShot:Sound = new Sound(this);
gunShot.attachSound ("gunshot"); //this is the linkage identifier, not the file name
gunShot.play();
}
If it's embedded in the button/movieClip, then a simple
Code:
on (release){
play();
}
would work.
As a note, keeping all the code in one or two spots, rather than actually putting code on your buttons directly, is a good idea for a couple of reasons:
1) it's easier to find everything.
2) if you make the switch to AS 3.0 you have to do it this way.
So, I would rather see this (placed just in a frame, not on the movie itself anywhere):
Code:
var gunShot:Sound = new Sound(this);
gunShot.attachSound ("gunshot"); //this is the linkage identifier, not the file name
button.onRelease = function(){
gunShot.play();
}
Good luck.
Dragontech Media
Magic.Fire.Content
-
hi CJ,
Yes the sound is in my library,
I have tried this code:
on (release){
var gunShot:Sound = new Sound(this);
gunShot.attachSound ("gunshot"); //this is the linkage identifier, not the file name
gunShot.play();
}
and get this error: gunShot.play(); There is no method with the name 'play'.
I assume its because i am a real n00b with AS2!
The instance that this code needs to work on is "crossHair" does this affect the code above?
Thanks folks.
-
Media Developer
Whoops. I meant gunShot.start(); Sorry about that.
Dragontech Media
Magic.Fire.Content
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
|