This content has been marked as final. Show 6 replies
Not to be a bother or anything, but I would really like it if this could be answered, thanks.
I suppose nobody answers you because you're asking how to walk but don't even know how to crawl... ;-)1 person found this helpful
First I would not recommend to use the behaviors. They will produce some automatic code which will be hard to understand for you. You can get the same result with like 5 lines of code...
Try the following steps (I'm working on Windows with Flash 8, so if you have another system it may be different...)
- go to file menu and open a new FLA (Flash Document)
- go to file->import->import to library
- choose a wav or mp3 sound and click open so you can nsee the sound in the library now
- right click it and choose "linkage"
- Check "export for ActionScript" and give it a name in the "Identifier" textfield, just call it "sound1"
- Confirm the dialog. Now create a new symbol in the library to make a button (right click in library -> new symbol)
- In the "Create New Symbol" dialog choose button as type, give it a name and confirm with ok
- Draw a rectangle or something so that we have something to click on.
- Now change back to the main frame in the scene and drag an instance of your button to the scene
Everything you need is in the scene, now the coding part:
- click on your button in the main frame (dont double click) just that it is highlighted
- now open up the actions and attach the following code to your button:
- then click somewhere in the scene to deselect the button and open the actions on the main frame
- attach this code:
var mySound1:Sound = new Sound();
Voila! If you now start your animation (CTRL+ENTER) it plays a sound when the button is pressed.
Here you can download it:
If this was too much for you, I recommend you read some basic flash tutorials on the net or buy a good book.
Jeese man, thx. Easy to understand, got it done in like 5 mins. Thx for the help, works great. One last question if it's not too much... how would I make it so that when I click on a different button, it plays another audio file BUT stops the other audio file from playing. If this is too much then I can live with this, but that would be a great improvement for what im doing.
I think I can answer this, too ;-)1 person found this helpful
But before that I give you the advice to use the F1 button in flash :-) It's a great helper if you eplore unknown terrain. Maybe it's a littble bit hard to read when you start with flash, but has almost anything you need.
If you just type "Sound" in flash then press F1 it takes you to the reference of the class Sound. Where you find all important methods and properties of the Sound class.
There you are Sound.stop() is all you need. Just change the code on the button to something like this:
This is ok if you have like two or three buttons. If there are more I would prefer to use a loop to stop all other sounds.
Or even better, if there should be no other sounds than the one sound the button triggers just use the global stopAllSounds() function like this:
It's easy, isn't it?
Feel free to come back and ask again if you have problems.
Just an important note:1 person found this helpful
This way we playback the sound is ok for small soundfiles. But if you plan to playback bigger mp3 songs it's not the right way, because all the sound files are included in the swf file.
You can control which compression is used when you righ click the sound and chose "properties". So big sound file will result in a big swf file or you really chose extreme compression and with this bad sound quality. So your visitors have wait long before the animation even start or have ugly sound.
That's why there is a possibility to stream files...
Thank you man u r so good.