FlashDevelop:加载/播放声音文件的推荐方式
我不确定这是 FlashDevelop 还是一般的 ActionScript3 问题,但是,我正在尝试找出将声音文件添加到我的 flashdevelop 项目的最佳方法。
例如,我发现如果我将 .mp3 文件放在项目的 bin 文件夹中,我可以使用以下代码行加载/播放它们
var sndreq:URLRequest = new URLRequest("foo.mp3");
var sound:Sound = new Sound();
sound.load(sndreq);
sound.play();
将所有声音文件移动到项目的 bin 目录似乎有点痛苦(但如果这就是所需要的,那就这样吧)。当我右键单击媒体文件时,我看到有一个“添加到库”选项,但我不确定它的效果是什么(我希望这意味着它会自动复制到项目的 bin 目录中,但是没有这样的运气)。
所以,我的问题是:假设我只有 flashdevelop 而没有 Flash CS3/4,这是加载本地声音文件的推荐方法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如上面的帖子所述,您问题的第一部分是一个简单的路径问题。我发现为所有动态加载的资源(xml、图像、声音)等构建一个文件结构很好。保持 bin 目录干净整洁。
更大的问题是关于在运行时嵌入与加载资源。我不止一次地完成一个项目,发现我的单个 swf(嵌入了所有资源)已经变得相当大,现在需要很长的前期加载。作为开发人员,这可能会让您的生活变得更轻松,但对于最终用户来说却不太好。
这些天我最喜欢的做法是仅嵌入应用程序首次启动所需的内容,然后尽可能隐藏其余资产的负载。不要让您的用户等待看到您的精彩作品!
实际上,我使用 flash ide 来打包作为 swf 发布的资产集(尽管您可以通过 FD 嵌入来完成同样的事情)。我在运行时定位这些 swf,并从应用程序域中提取类。我主要构建微型网站,并且倾向于将内容部分(“页面”)分解为可加载的 swf。加载目标 swf 后,页面即可用于导航。
另一种方法是使用 BulkLoader 之类的东西,或者更好的是 Greensock 的 LoaderMax(具有一些出色的队列功能)来加载单个资源。
希望有帮助。干杯!
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!
如果您只使用 FlashDevelop,您有两个选择。您可以在编译时嵌入资源,以便使用 [embed ...] 语句将它们打包。
http://www.bit-101.com/blog/?p=853
另请注意,在 FlashDevelop 中,您实际上可以右键单击资源,然后单击“插入到文档中”,这将自动为您写入嵌入行。
或者,您可以在运行时加载资源。所以像现在一样使用 URLRequest 方法。但你并不局限于 bin 目录。您可以:
无论是否动态加载,您都需要一个路径。
总的来说,如果您不需要动态,请嵌入资源。
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:
Regardless if you are loading dynamically you will require a path to it.
Overall if you don't need dynamic, embed the resources.