Just wondering if anyone could help me with this. I’m new to actionscript, and am building an application that plays some sounds when buttons are clicked.
It’s got 5 tabs, and will give the user the options to play about 10 sounds per tab.
I have initially been loading the sounds on runtime, so whenever the user clicked a button to play that sound, I would do something like:
var sound:Sound = new Sound(new URLRequest("assets/hello.mp3"));
sound.play();
I’m not sure, but I don’t think this is very good, since I would be loading that sound over and over again if the user pressed the button too many times.
I then thought about embedding the sound in each of the views (I have one view per tab), so would embed the sounds whenever the view was loaded. I think this is a better options, but still am a bit unsure about how the embed works exactly.
[Embed('assets/hello.mp3')] private var hello_mp3:Class;
I suppose it simply embeds the mp3 files when the swf is compiled (making it bigger), but they would not be loaded anymore once the app starts, or once that view is initialized again.
My question is: Is this the right approach to take? Is there any better way I can accomplish this? Is embedding the right solution for my problem?
Thanks in advance
The first solution works fine, it won’t make your SWf bigger and once the sound has been loaded once, it will be cached by Flash Player, so the sound is not loaded again and again.
This is a more efficient approach, sounds that are not played will not be loaded.
Bear in mind that when the button is pressed for the first time , you may experience a slight delay due to the sound being loaded.
In order to avoid this, you can load some sounds as external assets, meaning that after your SWF has loaded, you can call a function that will load some or all of the sounds, depending on the needs of the app. Your SWF will not be bloated and the button click will be more responsive.