闪存播放/暂停声音切换按钮 [英] Flash Play/Pause sound toggle button

查看:163
本文介绍了闪存播放/暂停声音切换按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我GOOGLE和google搜索,但没有得到那里的或过时的教程。任何人都知道怎么做,所以我可以切换音频使用ActionScript 3的Flash按钮?

I've googled and googled but got no where or outdated tutorials. Anyone know how to make it so I can toggle audio with buttons using ActionScript 3 on Flash?

推荐答案

要切换播放/暂停,你将需要记录在用户已暂停音频的位置。

To toggle play/pause you will need to record the position of where the user has paused the audio.

要在您的屏幕截图使用一个声音从库一样,你需要做的声音文件提供给您的ActionScript。

To use a sound from the library like in your screenshot, you need to make that sound file available to your Actionscript.

首先,右键单击库中的声音文件,然后单击属性... 。在属性窗口中,选中复选框为ActionScript导出。更改类名的东西你自己,像 MySong

First, Right click the sound file in your Library and click on Properties.... Inside the Properties window, check the box to Export for Actionscript. Change the Class name to something of your own, like MySong.

现在在你的code而不是指向外部的声音文件,你会为mySound MySong

Now inside your code instead of pointing to an external Sound file, you will make mySound an instance of MySong.

var isPlaying:Boolean;
var pausePosition:Number;
var myChannel:SoundChannel = new SoundChannel();
// edited mySound to use an internal sound file with Class of MySong
var mySound:Sound = new MySong();
var myButton:MovieClip;

myButton.addEventListener(MouseEvent.CLICK, playPauseClicked);

myChannel = mySound.play();
isPlaying = true;

function playPauseClicked(e:MouseEvent):void
{
    if (isPlaying) {
        pausePosition = myChannel.position;
        myChannel.stop();
        isPlaying = false;
        // change the display of your button to show the pause state
    } else {
        myChannel = mySound.play(pausePosition);
        isPlaying = true;
        // change the display of your button to show the playing state
    }
}

要使用一个外部文件

您需要使用URLRequest类为指向的MP3文件的位置。如果该文件是在同一目录中发布的SWF文件时,它应该是这样的。

You would need to use the URLRequest class to point to where the mp3 file is located. If the file was in the same directory as your published swf file it would look like this.

var mySound:Sound = new Sound(new URLRequest("whatever.mp3"));

这篇关于闪存播放/暂停声音切换按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆