Reputation: 2451
I'm not sure if this is a FlashDevelop or a general ActionScript3 question, however, I am trying to figure out the best way to add sound files to my flashdevelop project.
For example, I've found that if I place .mp3 files within the my project's bin folder I can load/play them with the following lines of code
var sndreq:URLRequest = new URLRequest("foo.mp3");
var sound:Sound = new Sound();
sound.load(sndreq);
sound.play();
It seems like kindof a pain to move all my sound files to my project's bin directory (but if that's what it takes so be it). I see that there's an "add to library" option when I right click on my media files, but I'm not sure what the effect of that is (I was hoping that meant it would be automatically copied to the project's bin directory, but no such luck).
So, my question is: supposing I only have flashdevelop and not Flash CS3/4, is this the recommended way for loading local sound files?
Upvotes: 2
Views: 3996
Reputation: 4244
The first part of your question is a simple pathing issue, as noted by the above post. I find it nice to build a file structure for all your dynamically loaded assets (xml, images, sounds) etc. Keeps your bin directory clean and tidy.
The bigger question is about embedding vs loading assets at runtime. I've, more than once, come to the completion of a project, to find that my single swf (with all assets embedded) has grown pretty large, and now requires a long up-front load. This may make life for you, as a developer easier, but its not very nice for the end user.
My favored practice these days is to embed only the content needed for the initial launch of the app and then hide the load of the rest of the assets as much as possible. Don't make your users wait to see your amazing work!
I actually use the flash ide to package sets of assets that I publish as swfs (though you could accomplish the same thing via FD embeds). I target these swfs at runtime and extract classes from the application domain. I predominately build microsites, and I tend to break sections of content ("pages") into loadable swfs. Once the target swf has loaded, the page becomes available for navigation.
An alternative route is to use something like BulkLoader, or, better yet, Greensock's LoaderMax (has some excellent queue features) for loading individual assets.
Hope that helps. Cheers!
Upvotes: 4
Reputation: 58322
If you are only using FlashDevelop you have two options. You can embed resources at compile time, so they are packaged, using the [embed ...] statement.
http://www.bit-101.com/blog/?p=853
Also note that while in FlashDevelop you can actually right click on a resource, and click 'Insert into document' which will automatically write the embed line for you.
Alternatively you can load resources in at runtime. So using the URLRequest method like you are now. But you are not limited to the bin directory. You can:
new URLRequest("../../../../../foo.mp3");
// or
new URLRequest("www.stackoverflow.com/fakeresources/foo.mp3");
Regardless if you are loading dynamically you will require a path to it.
Overall if you don't need dynamic, embed the resources.
Upvotes: 2