Starting sounds from classes.

Subscribe to Starting sounds from classes. 11 posts, 3 voices

Sign in to reply


 
avatar for DrunkenOrc DrunkenOrc 105 posts
Flag Post

Alright, to be frank, I have no idea how to make a sound play from inside of a class.


class RedTower extends MovieClip {
	var lowbuzz:Sound;
	function onLoad() {
		lowbuzz.attachSound('lowbuzz');
	}
	function onEnterFrame() {
		if (this.hitTest(_root.TheCharacter._x, _root.TheCharacter._y, true)) {
			_root.TheCharacter.redtouch = true;
                                      // The above line has nothing to do with the sound.
			lowbuzz.start(0, 1);
		}
	}
}

I patched together this sound emmiting code from some AS2 tutorials and it doesn’t work. Frankly, I’m not supprised. Can anyone give me a hand?

 
avatar for Cloud_9ine Cloud_9ine 2242 posts
Flag Post

Well although in AS3, Colby made a real nice sound managing class here I made one in AS3 also with some advanced looping functionality, but if you look at Colby’s source you could probably get the gist. Unless sound in AS2 is completely different from AS3.

 
avatar for jonathanasdf jonathanasdf 1592 posts
Flag Post

try using another var other than lowbuzz for the var name.

and cloud, that is pretty offtopic from his question. But anyways I made a similar sound managing class myself too, with crossfading :)

 
avatar for Cloud_9ine Cloud_9ine 2242 posts
Flag Post

Well yea its a bit off topic, I was merely suggesting he look as Colby’s source for some hints because I was too lazy to write it out.

Oh yea, mine, although isn’t quite made to, can crossfade, AND set keys/buttons for individual sound effect and music muting.

 
avatar for jonathanasdf jonathanasdf 1592 posts
Flag Post

same >:(

Anyways, yeah I see. But it doesn’t help because as2 and as3 is completely different, and he isn’t looking for a manager class.

 
avatar for DrunkenOrc DrunkenOrc 105 posts
Flag Post

I tried changing the var name to hitnoise, but that did nothing.

class RedTower extends MovieClip {
	var hitnoise:Sound;
	function onLoad() {
		hitnoise.attachSound('lowbuzz');
	}
	function onEnterFrame() {
		if (this.hitTest(_root.TheCharacter._x, _root.TheCharacter._y, true)) {
			_root.TheCharacter.redtouch = true;
			hitnoise.start(0, 1);
		}
	}
}

Any other ideas?

 
avatar for Cloud_9ine Cloud_9ine 2242 posts
Flag Post

Your sure the linkage of the sound is ‘lowbuzz’? That often screws me over so badly sometimes. Damn I’m so bored.

Also set it up so it will play a sound right away instead of waiting for the condition to play it. So maybe put the play on the enterframe. Sure it will sound ugly but it will tell you if its the sound or the if.

 
avatar for jonathanasdf jonathanasdf 1592 posts
Flag Post

EDIT

LOLOLOL cannot believe I didn’t see this.
You never instantiated hitnoise. put hitnoise = new Sound() somewhere.

 
avatar for Cloud_9ine Cloud_9ine 2242 posts
Flag Post

ROFL, I should have noticed that too, but liek I said, I’m lazy. But yea. Either way, I suggest if you go on to AS3, to us a nice little sound engine for all your sound work, it’s so simple and organized. :P

 
avatar for DrunkenOrc DrunkenOrc 105 posts
Flag Post

Ah, that was the problem. Thank you.

 
avatar for Cloud_9ine Cloud_9ine 2242 posts
Flag Post

My Sound manager is still better. It (mostly) implements Urbansqualls coding standards.

Sign in to reply


Click Here