Flash CS4控制AS3中动画声音的播放或停止
平面设计 2021-07-03 14:35www.168986.cn平面设计培训
今天有闪友问到如何控制AS3中的声音问题,用狼蚁网站SEO优化的小实例说明
以上就是Flash CS4控制AS3中动画声音的播放或停止方法,希望能对大家有所帮助!
复制代码
代码如下:/
As3Sound.as
/
package {
import flash.display.Sprite;
import flash.events.;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash..URLRequest;
import flash.utils.Timer;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.filters.DropShadowFilter;
public class As3Sound extends Sprite {
private var url:String = "http://sxl001.xfyun./music/lib/myRussia.mp3";
private var soundFactory:Sound;
private var channel:SoundChannel;
private var positionTimer:Timer;
private var play_btn:Sprite;
private var s_btn:Sprite;
private var d_filtersropShadowFilter=new DropShadowFilter(5,45,0x000000,80,8,8);
//用于记录音乐现在是否为暂停状态
private var bSoundS:Boolean = false;
public function As3Sound() {
var sxl_txt:TextField = new TextField();
sxl_txt.text="CS4中如何控制声音的播放或停止的";
sxl_txt.autoSize=TextFieldAutoSize.LEFT;
sxl_txt.x=stage.stageWidth/2-sxl_txt.width/2;
sxl_txt.y=20;
addChild(sxl_txt);
var mp3_request:URLRequest = new URLRequest(url);
soundFactory = new Sound();
//成功加载数据后
soundFactory.addEventListener(Event.COMPLETE, pleteHandler);
//在存在可用于 MP3 声音的 ID3 数据时
soundFactory.addEventListener(Event.ID3, id3Handler);
//加载音乐错误时
soundFactory.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
//音乐加载中...
soundFactory.addEventListener(ProgressEvent.PROGRESS, progressHandler);
soundFactory.load(mp3_request);
channel = soundFactory.play();
//音乐播放完成
channel.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
//用Timer监听音乐的播放进度
positionTimer = new Timer(1000);
positionTimer.addEventListener(TimerEvent.TIMER, positionTimerHandler);
positionTimer.start();
//创建一个按钮,用于播放音乐
play_btn = new Sprite();
play_btn.graphics.beginFill(0xFFCC32);
play_btn.graphics.drawRoundRect(0, 0, 70, 18, 10, 10);
play_btn.graphics.endFill();
var play_txt:TextField = new TextField();
play_txt.text = "播放";
play_txt.x=18;
play_btn.x=50;
play_btn.y=100;
play_txt.selectable = false;
play_btn.addChild(play_txt);
play_btn.filters=[d_filters];
play_btn.addEventListener(MouseEvent.CLICK, soundPlay);
addChild(play_btn);
//创建一个按钮,用于停止音乐
s_btn = new Sprite();
s_btn.graphics.beginFill(0xFFCC32);
s_btn.graphics.drawRoundRect(0, 0, 70, 18, 10, 10);
s_btn.graphics.endFill();
s_btn.x=130;
s_btn.y=100;
var s_txt:TextField = new TextField();
s_txt.x=18;
s_txt.text = "暂停";
s_txt.selectable = false;
s_btn.addChild(s_txt);
s_btn.filters=[d_filters];
s_btn.addEventListener(MouseEvent.CLICK, soundS);
addChild(s_btn);
}
//监听音乐的播放进度
private function positionTimerHandler(event:TimerEvent):void {
var ybf:int = channel.position.toFixed(0);
var zcd:int = soundFactory.length;
var bfs:int = Math.floor(ybf/zcd100);
//trace("音乐总长度"+zcd, "音乐已播放"+ybf, "播放进度为"+bfs+"%");
}
//加载音乐完成时
private function pleteHandler(event:Event):void {
//trace("加载音乐完成: " + event);
}
//在存在可用于MP3声音的ID3数据时
private function id3Handler(event:Event):void {
//trace("音乐的ID3信息如下:");
for (var s in soundFactory.id3) {
//trace("\t", s, ":", soundFactory.id3[s]);
}
//trace("关于ID3信息介绍,请参见Sound类-->属性-->id3");
}
//加载音乐错误时
private function ioErrorHandler(event:Event):void {
//trace("加载音乐错误,错误信息如下" + event);
positionTimer.s();
}
//加载音乐时
private function progressHandler(eventrogressEvent):void {
var yjz:int = event.bytesLoaded;
var zcd:int = event.bytesTotal;
var bfs:int = Math.floor(yjz/zcd100);
//trace("音乐总长度"+zcd,"已加载: "+yjz, "加载进度为"+bfs+"%");
}
//音乐播放完成
private function soundCompleteHandler(event:Event):void {
//trace("音乐播放完成: " + event);
positionTimer.s();
}
//点击播放按钮事件
private function soundPlay(event:MouseEvent):void {
if (bSoundS) {
bSoundS = false;
channel = soundFactory.play(channel.position.toFixed(0));
}
}
//点击停止按钮事件
private function soundS(event:MouseEvent):void {
if (!bSoundS) {
bSoundS = true;
channel.s();
}
}
}
}
As3Sound.as
/
package {
import flash.display.Sprite;
import flash.events.;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash..URLRequest;
import flash.utils.Timer;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.filters.DropShadowFilter;
public class As3Sound extends Sprite {
private var url:String = "http://sxl001.xfyun./music/lib/myRussia.mp3";
private var soundFactory:Sound;
private var channel:SoundChannel;
private var positionTimer:Timer;
private var play_btn:Sprite;
private var s_btn:Sprite;
private var d_filtersropShadowFilter=new DropShadowFilter(5,45,0x000000,80,8,8);
//用于记录音乐现在是否为暂停状态
private var bSoundS:Boolean = false;
public function As3Sound() {
var sxl_txt:TextField = new TextField();
sxl_txt.text="CS4中如何控制声音的播放或停止的";
sxl_txt.autoSize=TextFieldAutoSize.LEFT;
sxl_txt.x=stage.stageWidth/2-sxl_txt.width/2;
sxl_txt.y=20;
addChild(sxl_txt);
var mp3_request:URLRequest = new URLRequest(url);
soundFactory = new Sound();
//成功加载数据后
soundFactory.addEventListener(Event.COMPLETE, pleteHandler);
//在存在可用于 MP3 声音的 ID3 数据时
soundFactory.addEventListener(Event.ID3, id3Handler);
//加载音乐错误时
soundFactory.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
//音乐加载中...
soundFactory.addEventListener(ProgressEvent.PROGRESS, progressHandler);
soundFactory.load(mp3_request);
channel = soundFactory.play();
//音乐播放完成
channel.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
//用Timer监听音乐的播放进度
positionTimer = new Timer(1000);
positionTimer.addEventListener(TimerEvent.TIMER, positionTimerHandler);
positionTimer.start();
//创建一个按钮,用于播放音乐
play_btn = new Sprite();
play_btn.graphics.beginFill(0xFFCC32);
play_btn.graphics.drawRoundRect(0, 0, 70, 18, 10, 10);
play_btn.graphics.endFill();
var play_txt:TextField = new TextField();
play_txt.text = "播放";
play_txt.x=18;
play_btn.x=50;
play_btn.y=100;
play_txt.selectable = false;
play_btn.addChild(play_txt);
play_btn.filters=[d_filters];
play_btn.addEventListener(MouseEvent.CLICK, soundPlay);
addChild(play_btn);
//创建一个按钮,用于停止音乐
s_btn = new Sprite();
s_btn.graphics.beginFill(0xFFCC32);
s_btn.graphics.drawRoundRect(0, 0, 70, 18, 10, 10);
s_btn.graphics.endFill();
s_btn.x=130;
s_btn.y=100;
var s_txt:TextField = new TextField();
s_txt.x=18;
s_txt.text = "暂停";
s_txt.selectable = false;
s_btn.addChild(s_txt);
s_btn.filters=[d_filters];
s_btn.addEventListener(MouseEvent.CLICK, soundS);
addChild(s_btn);
}
//监听音乐的播放进度
private function positionTimerHandler(event:TimerEvent):void {
var ybf:int = channel.position.toFixed(0);
var zcd:int = soundFactory.length;
var bfs:int = Math.floor(ybf/zcd100);
//trace("音乐总长度"+zcd, "音乐已播放"+ybf, "播放进度为"+bfs+"%");
}
//加载音乐完成时
private function pleteHandler(event:Event):void {
//trace("加载音乐完成: " + event);
}
//在存在可用于MP3声音的ID3数据时
private function id3Handler(event:Event):void {
//trace("音乐的ID3信息如下:");
for (var s in soundFactory.id3) {
//trace("\t", s, ":", soundFactory.id3[s]);
}
//trace("关于ID3信息介绍,请参见Sound类-->属性-->id3");
}
//加载音乐错误时
private function ioErrorHandler(event:Event):void {
//trace("加载音乐错误,错误信息如下" + event);
positionTimer.s();
}
//加载音乐时
private function progressHandler(eventrogressEvent):void {
var yjz:int = event.bytesLoaded;
var zcd:int = event.bytesTotal;
var bfs:int = Math.floor(yjz/zcd100);
//trace("音乐总长度"+zcd,"已加载: "+yjz, "加载进度为"+bfs+"%");
}
//音乐播放完成
private function soundCompleteHandler(event:Event):void {
//trace("音乐播放完成: " + event);
positionTimer.s();
}
//点击播放按钮事件
private function soundPlay(event:MouseEvent):void {
if (bSoundS) {
bSoundS = false;
channel = soundFactory.play(channel.position.toFixed(0));
}
}
//点击停止按钮事件
private function soundS(event:MouseEvent):void {
if (!bSoundS) {
bSoundS = true;
channel.s();
}
}
}
}
以上就是Flash CS4控制AS3中动画声音的播放或停止方法,希望能对大家有所帮助!
平面设计师
- 平面设计图怎么画 小学生画平面图
- 平面设计内容怎么写 平面设计的求职意向怎么写
- 平面设计图手绘 平面设计图手绘家具
- 平面设计多久能出师 平面设计要多久
- 女生做ui设计师有多累 女生为什么学ui的人很惨
- 哪里有学平面设计的学校 想学平面设计去哪里学
- 初学平面设计用哪个软件 平面设计初学者必备的
- 0基础学平面设计要多久 0基础自学平面设计
- 平面设计手绘培训 平面设计师培训班学费多少钱
- ui工作好找工作吗 ui好不好找工作
- 女生学室内设计吃香吗
- ps平面设计自学教程 平面设计ps入门教程
- 平面设计基础知识大全 平面设计基本常识
- 平面设计基础教学视频 平面设计教学零基础入门
- 平面设计基础教学 平面设计基础教学平时作业
- ui设计主要是学什么 ui设计一般是学什么