仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 872|回复: 8
打印 上一主题 下一主题

[学习教程] 带来一篇Flash CS4怎样把持动画声响的中断和播放-Flash actionscript

[复制链接]
活着的死人 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-15 20:48:38 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
AdobeFlashProfessionalCS5.5软件可以提供行业领先、用于制作具有表现力的交互式内容的授权环境。
poluoluo中心提醒:明天有闪友问到怎样把持AS3中的声响成绩,用上面的小实例申明。
明天有闪友问到怎样把持AS3中的声响成绩,用上面的小实例申明:

[media=wmv,250,220][/media]
/*
As3Sound.as
*/
package{
importflash.display.Sprite;
importflash.events.*;
importflash.media.Sound;
importflash.media.SoundChannel;
importflash.net.URLRequest;
importflash.utils.Timer;
importflash.text.TextField;
importflash.text.TextFieldAutoSize;
importflash.filters.DropShadowFilter;
publicclassAs3SoundextendsSprite{
privatevarurl:String="http://sxl001.xfyun.com/music/lib/myRussia.mp3";
privatevarsoundFactory:Sound;
privatevarchannel:SoundChannel;
privatevarpositionTimer:Timer;
privatevarplay_btn:Sprite;
privatevarstop_btn:Sprite;
privatevard_filtersropShadowFilter=newDropShadowFilter(5,45,0x000000,80,8,8);
//用于纪录音乐如今是不是为停息形态
privatevarbSoundStop:Boolean=false;
publicfunctionAs3Sound(){
varsxl_txt:TextField=newTextField();
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);
varmp3_request:URLRequest=newURLRequest(url);
soundFactory=newSound();
//乐成加载数据后
soundFactory.addEventListener(Event.COMPLETE,completeHandler);
//在存在可用于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=newTimer(1000);
positionTimer.addEventListener(TimerEvent.TIMER,positionTimerHandler);
positionTimer.start();
//创立一个按钮,用于播放音乐
play_btn=newSprite();
play_btn.graphics.beginFill(0xFFCC32);
play_btn.graphics.drawRoundRect(0,0,70,18,10,10);
play_btn.graphics.endFill();
varplay_txt:TextField=newTextField();
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);
//创立一个按钮,用于中断音乐
stop_btn=newSprite();
stop_btn.graphics.beginFill(0xFFCC32);
stop_btn.graphics.drawRoundRect(0,0,70,18,10,10);
stop_btn.graphics.endFill();
stop_btn.x=130;
stop_btn.y=100;
varstop_txt:TextField=newTextField();
stop_txt.x=18;
stop_txt.text="停息";
stop_txt.selectable=false;
stop_btn.addChild(stop_txt);
stop_btn.filters=[d_filters];
stop_btn.addEventListener(MouseEvent.CLICK,soundStop);
addChild(stop_btn);

}
//监听音乐的播放进度
privatefunctionpositionTimerHandler(event:TimerEvent):void{
varybf:int=channel.position.toFixed(0);
varzcd:int=soundFactory.length;
varbfs:int=Math.floor(ybf/zcd*100);
//trace("音乐总长度:"+zcd,"音乐已播放:"+ybf,"播放进度为:"+bfs+"%");
}
//加载音乐完成时
privatefunctioncompleteHandler(event:Event):void{
//trace("加载音乐完成:"+event);
}
//在存在可用于MP3声响的ID3数据时
privatefunctionid3Handler(event:Event):void{
//trace("音乐的ID3信息以下:");
for(varsinsoundFactory.id3){
//trace("        ",s,":",soundFactory.id3);
}
//trace("关于ID3信息先容,请拜见Sound类-->属性-->id3");
}
//加载音乐毛病时
privatefunctionioErrorHandler(event:Event):void{
//trace("加载音乐毛病,毛病信息以下:"+event);
positionTimer.stop();
}
//加载音乐时
privatefunctionprogressHandler(eventrogressEvent):void{
varyjz:int=event.bytesLoaded;
varzcd:int=event.bytesTotal;
varbfs:int=Math.floor(yjz/zcd*100);
//trace("音乐总长度:"+zcd,"已加载:"+yjz,"加载进度为:"+bfs+"%");
}
//音乐播放完成
privatefunctionsoundCompleteHandler(event:Event):void{
//trace("音乐播放完成:"+event);
positionTimer.stop();
}
//点击播放按钮事务
privatefunctionsoundPlay(event:MouseEvent):void{
if(bSoundStop){
bSoundStop=false;
channel=soundFactory.play(channel.position.toFixed(0));
}
}
//点击中断按钮事务
privatefunctionsoundStop(event:MouseEvent):void{
if(!bSoundStop){
bSoundStop=true;
channel.stop();
}
}
}
}
运行时,它可以跨浏览器和操作系统、原汁原味地呈现具有表现力的应用程序、内容和视频,功能强大,兼容性高。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-12 17:50

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表