flash 调用 脚本_Flash脚本-动态调用声音

flash 调用 脚本

Download the sample files here.

在此处下载示例文件

Imagine you have a Flash application that allows the user to select 50 different songs. If you store 50 different song files wiht the application, the file size of the project will be huge.

假设您有一个Flash应用程序,该应用程序允许用户选择50首不同的歌曲。 如果使用该应用程序存储50个不同的歌曲文件,则项目的文件大小将很大。

How can we avoid this? We’ll create 50 swf files, each containing a different song. We’ll call the file dynamically, according to the user’s choice of song.

我们如何避免这种情况? 我们将创建50个swf文件,每个文件包含不同的歌曲。 我们将根据用户选择的歌曲来动态调用文件。

Sound difficult? It’s not! Let’s get started! Note that this tutorial assumes that you’ve already imported a sound file into Flash.

听起来很难? 不是! 让我们开始吧! 请注意,本教程假定您已经将声音文件导入Flash。

1. Create a new Flash movie, and on its first frame, add the following script:

1.创建一个新的Flash电影,并在其第一帧上添加以下脚本:

function mysound (flag)
{
mysound = new Sound(this);
mysound.stop();
//test is id of the sound file
mysound.attachSound("test");
//if true play
if(flag){mysound.start();}
//if false stop
if(!flag){mysound.stop();}
}

2. Open the library panel and right click the sound file. Go to "linkage properties", and select the radio button that reads "Export this symbol". Give the symbol an id name in the identifier field.

2.打开库面板,然后右键单击声音文件。 转到“链接属性”,然后选择显示为“导出此符号”的单选按钮。 在标识符字段中为符号提供一个ID名称。

1098_tool1

3. Now drag the sound file on to the stage from the library.

3.现在,将声音文件从库中拖到舞台上。

4. Select the sound layer and go to "Sound" panel as shown below. Apply the settings shown here.

4.选择声音层,然后转到“声音”面板,如下所示。 应用此处显示的设置。

1098_tool2

5. Save the movie you as "sound.fla", and publish the movie swf only.

5.将电影另存为“ sound.fla”,然后仅发布电影swf。

6. Open a new flash movie, and create two buttons as shown above. Label the first one "play sound", and the second "stop sound".

6.打开一个新的Flash影片,并创建两个按钮,如上所示。 标记第一个为“播放声音”,第二个为“停止声音”。

8. Create a blank movie clip. Give it an instance name of "snd".

8.创建一个空白的影片剪辑。 给它指定实例名称“ snd”。

9. In the first frame, insert the action:

9.在第一帧中,插入动作:

loadMovie("sound.swf","/snd");

10. Right click the "play sound" button and insert the action:

10.右键单击“播放声音”按钮并插入动作:

on (release) { _root.snd.mysound(true);}

11. Right click the "stop sound" button and insert the action:

11.右键单击“停止声音”按钮并插入操作:

on (release) { _root.snd.mysound(false);}

You’re done! Play the movie!

你完成了! 播放电影!

Using this technique, you can call as many sound files as you want.

使用此技术,您可以根据需要调用任意数量的声音文件。

翻译自: https://www.sitepoint.com/call-sounds-dynamically/

flash 调用 脚本

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值