[AS3]as3删除对象与删除侦听监听
[AS3]as3删除对象与删除侦听监听
[AS3]as3删除对象与删除侦听监听
- package com{
- import flash.display.MovieClip;
- import flash.events.Event;
- dynamic public class removeCon extends MovieClip{
- private var lis:Array;//定义一数组保存侦听
- public function removeCon() {
- lis = new Array();
- addEventListener(Event.REMOVED,remove);//侦听删除事件
- }
- //重写addEventListener,在增加侦听的时候..把相应的事件保存到数组
- override public function addEventListener(type:String, listener:Function,
useCapture:Boolean = false, priority:int = 0,
useWeakReference:Boolean = false):void {- lis.push([type,listener,useCapture]);
- super.addEventListener(type,listener,useCapture,priority,useWeakReference);
- }
- //cuplayer.com"自c我毁灭"的方法
- private function remove(e:Event):void {
- if (e.currentTarget!=e.target) {
- return;
- }
- stop();
- //cuplayer.com删除子对象
- trace("删除前有子对象",numChildren);
- while (numChildren > 0) {
- removeChildAt(0);
- }
- trace("删除后有子对象",numChildren);
- //cuplayer.com删除动态属性
- for (var k:String in this) {
- trace("删除属性",k);
- delete this[k];
- }
- //cuplayer.com删除侦听
- trace("num=" + lis.length);
- for (var i:uint = 0; i < lis.length; i++) {
- trace("删除Listener", lis[i]);
- removeEventListener(lis[i][0],lis[i][1],lis[i][2]);
- }
- lis=null;
- }
- }
- }
使用方法:
- import removeCon;
- var mc:MovieClip = new removeCon();
- mc.addEventListener(Event.ADDED,aaaa);
- mc.addEventListener(Event.ADDED_TO_STAGE,aaaa);
- mc.addEventListener(Event.ENTER_FRAME,aaaa);
- mc.addEventListener(MouseEvent.CLICK,aaaa);
- mc.addEventListener(MouseEvent.MOUSE_DOWN,aaaa);
- mc.a="http://www.cuplayer.com";
- mc.b="我是动态属性2";
- mc.name="我是MC";
- addChild(mc);
- function aaaa(e:Event) {
- }
- removeChild(mc);
- mc=null;
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...