关于加载外部SWF文件的声音控制

news/2024/7/3 23:04:31

 声明:欢迎任何人和组织转载本blog中文章,但必须标记文章原始链接和作者信息。

本文链接:http://blog.csdn.net/li_007/archive/2009/03/30/4037090.aspx

开拓进取的小乌龟------->CSDN点滴点点滴滴Blog

今天加载了一个有声音的swf,然后在没播放完成的时候,又加载了另一个swf,同样是有声音的,结果发现奇怪的事情出现了,先前的swf视频是销毁,unload不见了,可是声音还是在播放的,结果发现内存也没有被释放,过了好久才释放(我的代码中如果播放完成或者什么的都是有销毁的过程的,不过有点对Actionscript 3的垃圾回收机制搞不懂了,现在还在思考中。。。。),还害的PM等了我好长时间。

 

首先来说说声音的问题吧,其实以前是没注意,今天才发现,后来查查Adobe Docs后发现也很简单,先看看Adobe Docs中flash.media.sound class的描述截图:

Flash Media Sound

特别是最后红色线标记的,告诉我们控制外部加载的swf file,使用SoundMixer Class的属性,OK。看看SoundMixer类后就发现很简单,这个类提供了静态的方法StopAll来停止当前正在播放的声音。也看截图吧:

Flash Media SoundMixer StopAll

 好了,修改前面文章发的那个类(http://blog.csdn.net/li_007/archive/2009/03/28/4032276.aspx)如下:

 // // CLoadMedia.as // // you can load external swf and pictures used this class // // Written by Leezhm, 7th Nov, 2008 // Contact : Leezhm@126.com // Copyright @ Luxoom.cn // Last Modified by Leezhm on 30th March, 2009 // package Srcs { import flash.display.DisplayObjectContainer; import flash.display.Loader; import flash.display.MovieClip; import flash.display.LoaderInfo; import flash.events.Event; import flash.events.MouseEvent; import flash.net.URLRequest; import flash.media.SoundMixer; public class CLoadMedia { private var _file:String = ""; private var _loader:Loader; private var _request:URLRequest; private var _display:DisplayObjectContainer; private var _currentMC:MovieClip; public static const VIDEO_IS_OVER:String = "videoisover"; public function CLoadMedia(str:String, dis:DisplayObjectContainer) { if ("" != str) { this._file = str; } else { trace("the path of extern file is null!!!"); } if (null != dis) { this._display = dis; } } public function Loading():void { if (null == this._request) { this._request = new URLRequest(this._file); } if (null == this._loader) { this._loader = new Loader(); } this._loader.load(this._request); this._loader.contentLoaderInfo.addEventListener(Event.INIT, OnContentInit); this._display.addChild(this._loader); } public function get CurrentMovieClip():MovieClip { if (null != this._currentMC) { return this._currentMC; } else { return null; } } private function OnContentInit(evt:Event = null):void { this._loader.contentLoaderInfo.removeEventListener(Event.INIT, OnContentInit); if (3 == evt.target.actionScriptVersion) { evt.target.addEventListener(Event.COMPLETE, OnLoadCompleted); } else { trace("the actionscript version of swf file is incorrect!!!"); } } private function OnLoadCompleted(evt:Event = null):void { this._display.visible = true; this._loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, OnLoadCompleted); this._currentMC = MovieClip(evt.target.content); evt.target.content.addEventListener(Event.ENTER_FRAME, OnLoaderEnterFrame); this._loader.addEventListener(MouseEvent.CLICK, OnLoaderClick); } private function OnLoaderEnterFrame(evt:Event = null):void { if (null != this._currentMC && MovieClip(evt.target).currentFrame == this._currentMC.totalFrames) { SoundMixer.stopAll(); this._currentMC = null; if (null != this._request) { this._request = null; } if (null != this._loader) { this._loader.removeEventListener(MouseEvent.CLICK, OnLoaderClick); this._loader.dispatchEvent(new Event(CLoadMedia.VIDEO_IS_OVER)); this._display.removeChild(this._loader); this._display = null; this._loader.unload(); this._loader = null; } evt.target.removeEventListener(Event.ENTER_FRAME, OnLoaderEnterFrame); } } private function OnLoaderClick(evt:MouseEvent = null):void { SoundMixer.stopAll(); this._currentMC = null; if (null != this._request) { this._request = null; } if (null != this._loader) { this._loader.removeEventListener(MouseEvent.CLICK, OnLoaderClick); this._loader.dispatchEvent(new Event(CLoadMedia.VIDEO_IS_OVER)); this._display.removeChild(this._loader); this._display = null; this._loader.unload(); this._loader = null; } evt.target.removeEventListener(Event.ENTER_FRAME, OnLoaderEnterFrame); } } }

测试,能跟达到要求,实现控制,OK,大功告成,回家了。。。。。。。

 

关于那个内存的释放的问题,要慢慢仔细研究后在来同大家分享。

转载于:https://www.cnblogs.com/leezhm/archive/2009/03/30/2560323.html


http://www.niftyadmin.cn/n/547275.html

相关文章

计算机操作系统中有三个用户进程,计算机操作系统三章习题答案.doc

第三章 处理机调度与死锁030110011020101进程调度是从 选择一个进程投入运行。A.就绪队列B.等待队列C.作业后备队列D.提交队列030110011020100A030110022020101支持多道程序设计的操作系统在运行过程中,不断地选择新进…

The unique identifier of the win32 class is the class name

The unique identifier of the win32 class is the class name in one processcode:转载于:https://www.cnblogs.com/LittleFox/archive/2009/04/07/1431110.html

【转】你真的了解word-wrap和word-break的区别吗?

原文在这里: http://www.cnblogs.com/2050/archive/2012/08/10/2632256.html

电大计算机专业软件工程试题,2021国家开放大学电大本科《软件工程》期末试题及答案(试卷号:1260)...

2021国家开放大学电大本科《软件工程》期末试题及答案(试卷号:1260) 一、选择题,请从四个可选项中选择正确答案。(60分,每题3分) 1.可行性研究的主要任务是( )。A. 确定系统做什么 B.确定性能 C.确定功能 D…

delphi获取当前计算机所有盘符

GetDriveType(路径) 判断一个磁盘驱动器的类型 返回一个整数 0 驱动器类型不确定 1 系统目录不存在 2 DRIVE_REMOVABLE 是可移动驱动器 3 DRIVE_FIXED 是固定驱动器 4 DRIVE_REMOTE 是网络驱动器 5 DRIVE_CDROM 是CD-ROM驱动器 6 DRIVE_RAMDISK 是虚拟驱动器 functiongetP…

TIME_WAIT状态

(转)TIME_WAIT状态根据TCP协议定义的4次握手断开连接规定,发起socket主动关闭的一方socket将进入TIME_WAIT状态,TIME_WAIT状态将持续2个MSL(Max Segment Lifetime),在Windows下默认为4分钟,即240秒,TIME_WAIT状态下的socket不能被回收使用. 具体现象是对于一个处理大量短连接的…

基于web的计算机配件销售系统,javaweb电脑配件销售管理系统

今天记录的项目是基于javaweb的电脑配件销售管理系统,基于javaweb的电脑配件销售管理系统项目是这么回事:采用当前非常流行的B/S体系结构,以JAVA作为开发技术,主要依赖SSM技术框架,mysql数据库建立本系统。基于javaweb的电脑配件销售管理系统…

listener配置

刚才看见一篇很好的文章,转载一下: http://www.cnblogs.com/hellojava/archive/2012/12/26/2833840.html 以下文章完全为复制粘贴。 前言:之前写了一篇关于Filter的文章:http://tianweili.github.io/blog/2015/01/26/java-filter/…