I have been doing a lot of work in trying to minimize memory and file size in my flash/actionscript projects, because of the structure of actionscript 3 most of this is a manual process. One of the first things you can do is when adding an event listener, use the optional parameters:
_btn.addEventListener(MouseEvent.CLICK, btnClick, false, 0, true);
The last optional parameter in the addEventListener function is useWeakReference, which by default is set to false, according to the ActionScript 3.0 Documentation, this parameter “Determines whether the reference to the listener is strong or weak. A strong reference (the default) prevents your listener from being garbage-collected. A weak reference does not.”
Another standard that I have imemented is to use the REMOVED_FROM_STAGE event in every class that I write. In this class I remove any display objects that I have added and remove all event listeners that those display objects have, because just removing an object does not do this and hose event listeners will still be there taken up memory and can hinder performance.
我一直在试图减少内存和文件大小在我的flash/ActionScript项目,由于ActionScript 3的这方面最结构,是一个手动过程。第一件事你可以做一个是当添加一个事件监听器,使用可选的参数:
_btn.addEventListener(MouseEvent.CLICK, btnClick, false, 0, true);
最后在addEventListener函数的可选参数useWeakReference,默认设置为false,根据ActionScript 3.0文档,此参数:“确定是否对侦听参考的强弱。强引用(默认值)可以防止垃圾回收收取。弱引用没有。”
另一个我imemented标准是在每个类使用我写的REMOVED_FROM_STAGE事件。在这个类中删除任何显示对象,我增加和删除所有事件监听器,这些显示对象的,因为就删除一个对象不这样做,事件事件监听器依然占用内存,可阻碍性能对象。
package
{
import flash.display.*;
import flash.events.*;
public class MyClass extends Sprite
{
private var _btn:Sprite;
//-----------------------------------
// CONSTRUCTOR
//-----------------------------------
public function MyClass():void
{
addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true);
}
//-----------------------------------
// INIT
//-----------------------------------
private function init(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
addEventListener(Event.REMOVED_FROM_STAGE, dispose, false, 0, true);
_btn = new Sprite();
_btn.addEventListener(MouseEvent.MOUSE_OVER, btnOver, false, 0, true);
_btn.addEventListener(MouseEvent.MOUSE_OUT, btnOut, false, 0, true);
_btn.addEventListener(MouseEvent.CLICK, btnClick, false, 0, true);
_btn.buttonMode = true;
addChild(_btn);
}
//-----------------------------------
// DISPOSE
//-----------------------------------
private function dispose(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
removeEventListener(Event.REMOVED_FROM_STAGE, dispose);
if(_btn)
{
_btn.removeEventListener(MouseEvent.MOUSE_OVER, btnOver);
_btn.removeEventListener(MouseEvent.MOUSE_OUT, btnOut);
_btn.removeEventListener(MouseEvent.CLICK, btnClick);
try
{
removeChild(_btn);
}
catch(e:Error){trace("error: MyClass: dispose: removeChild(_btn): " + e)}
_btn = null;
}
}
}
}
分享到:
相关推荐
在《Managing NFS and NIS》这本书的第一章中,作者深入浅出地介绍了网络的基础知识。这部分内容对于理解后续章节中的NFS(Network File System)和NIS(Network Information Service)至关重要。 #### 1.1 网络...
Pointers are powerful tools for managing memory, but they can also be dangerous if not handled correctly. An invalid pointer is one that points to an address that is not accessible or has been ...
Managing Gigabytes 很经典的关于大数据处理的书籍,废了很大力气转成pdf 编辑了目录。
Rex Black's Managing the Testing Process, a compendium of real-world advice on managing software testing successfully. It is a veritable hodge-podge of sample test documents and is filled with ...
- **Flash Translation Layer (FTL)**: This layer is crucial as it manages the translation between logical addresses used by the file system and physical addresses on the flash memory. It helps in ...
In the third edition of the classic Managing Projects with GNU make, readers will learn why this utility continues to hold its top position in project build software, despite many younger competitors...
1 Managing for Stakeholders, 1 2 Business in the Twenty-first Century, 20 3 The Basic Framework, 47 4 Stakeholders, Purpose, and Values, 74 5 Everyday Strategies for Creating Value for Stakeholders, ...
Managing Windows with VBScript and WMI 2004.chm 共享资源,
Managing Your Biological Data with Python 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权...
A+ Guide to Managing and Maintaining Your PC
《Managing Software Debt》一书由Chris Sterling撰写,旨在深入探讨技术债务的概念、原因及其对业务的影响,并提供一系列实用的策略来管理和减少这种债务。 #### 技术债务的概念与类型 技术债务可以分为几种不同...
《Managing and Mining Uncertain Data》一书不仅为读者提供了不确定数据管理和挖掘的基础理论框架,还展示了该领域最新的研究成果和技术进展。对于希望深入了解该领域的研究人员、工程师以及学生来说,本书是一本...
本书《Managing RAID on Linux》由Derek Vadala编写,是一本深入探讨如何在Linux环境下管理和配置RAID系统的专业教材。该书首先介绍了RAID的基本概念和技术背景,然后详细讲解了在Linux系统中实现RAID的各种方法,并...
Managing Projects with GNU make, 3rd Edition provides guidelines on meeting the needs of large, modern projects
### 使用与管理PPP详解 #### 一、PPP简介 ...以上仅为《Using and Managing PPP》这本书的部分内容概述。该书详细介绍了PPP协议的各个方面,并提供了实用的操作指南和技术细节,是一本值得深入研究的专业书籍。
Infrastructure as Code Managing Servers in the Cloud 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
Mike Meyers' CompTIA A+ Guide to Managing and Troubleshooting PCs Lab Manual(5th) 英文azw3 第5版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn...
developing and managing a successfull payment cards business