Flex\flash中的callLater()函数作用
Flash的fl组件和Flex的mx组件都有一个受保护方法callLater,callLater可以说是优化组件执行效率的一个杀手锏,极其有用。 package com.colorhook.tools{ import flash.display.DisplayObject; import flash.utils.Dictionary; import flash.events.Event; public class FrameCallLater implements ICallLater{ private var _target:DisplayObject; private var methods:Dictionary; private var inCallLaterPhase:Boolean=false; public function FrameCallLater(target:DisplayObject){ this._target=target; methods=new Dictionary(true); super(); } /** * defined by ICallLater,I write a class TimeCallLater to implement it also. */ public function call(fun:Function):void{ if (inCallLaterPhase||_target==null) { return; } methods[fun]=true; if (_target.stage != null) { _target.stage.addEventListener(Event.RENDER,callLaterDispatcher,false,true); _target.stage.invalidate(); } else { _target.addEventListener(Event.ADDED_TO_STAGE,true); } } private function callLaterDispatcher(event:Event):void { if (event.type == Event.ADDED_TO_STAGE) { _target.removeEventListener(Event.ADDED_TO_STAGE,callLaterDispatcher); _target.stage.addEventListener(Event.RENDER,true); _target.stage.invalidate(); return; } else { event.target.removeEventListener(Event.RENDER,callLaterDispatcher); if (_target.stage == null) { _target.addEventListener(Event.ADDED_TO_STAGE,true); return; } } inCallLaterPhase = true; for (var method:Object in methods) { method(); delete(methods[method]); } inCallLaterPhase = false; } public function get target():DisplayObject{ return _target; } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |