1.载入外部xml方法
注意点:如果将flash放在html中,as中xml的路径都是相对html的路径
2.鼠标跟随事件
注意点:用stage.addEventListener(MouseEvent.MOUSE_MOVE, FollowMe2);// FollowMe2跟随事件方法名,FollowMe2方法中必须加上event.updateAfterEvent();
这样鼠标可以更流畅
3.动态文本遮罩
注意点:如果动态文本无法正常显示设置过滤器
var txt_blur:BlurFilter = new BlurFilter(0, 0, 0);
intro.filters=[txt_blur];
设置动态遮罩:contentMc.mask=maskMC;
4.跳帧时无法读取帧里的元件
注意点:flash的跳帧延时问题,可以用Event.ENTER_FRAME事件监听是否读取到元件,读取到后移除监听(不知道是否有更好办法)
5.关于监听带参
通常设置一个事件都是
元件.addEventListener(事件名,事件处理方法);
在这里无法将这个事件的一些设置参数传进处理方法中
在这里分享一个工具类EventDpMediator.as
package CYPL.utils {
import flash.events.Event;
import flash.events.IEventDispatcher;
import flash.utils.Dictionary;
public class EventDpMediator {
private static var eventObj : Object;
private var _dispatcher : IEventDispatcher;
/**
* @dispatcher 目标对象
*/
public function EventDpMediator(dispatcher : IEventDispatcher) {
_dispatcher = dispatcher;
eventObj = {};
}
/**
* 注册事件
* @eventType 事件类型
* @handler 响应方法
* @arg 参数对象
*/
public function addEventListener(eventType : String,handler : Function,arg : Object = null) : void {
//trace("addEventListener:::", eventType)
removeEventListener(eventType, handler);
if(eventObj[eventType] == undefined) {
eventObj[eventType] = new Dictionary;
eventObj[eventType]["count"] = 0;
}
eventObj[eventType]["count"]++;
_dispatcher.addEventListener(eventType, eventObj[eventType][handler] = handlerX.call(null, handler, arg));
}
/**
* 删除事件
* @eventType 事件类型
* @handler 响应方法
*/
public function removeEventListener(eventType : String,handler : Function) : void {
if(!eventObj[eventType])return;
var __handler : Function = eventObj[eventType][handler];
if(__handler == null)return;
//trace("removeEventListener", eventType);
_dispatcher.removeEventListener(eventType, __handler);
delete eventObj[eventType][handler];
if(eventObj[eventType]["count"]-- == 0) {
delete eventObj[eventType]["count"];
delete eventObj[eventType];
}
}
private function handlerX(handler : Function,arg : Object) : Function {
var This : EventDpMediator = this;
return function(e : Event): void {
handler.call(null, This, e, arg);
};
}
}
}
使用例子:
/**
* @author:CYPL
* @用途:EventDispatcher的中介类,方便进行传递参数
* @date:2009.7.14
* @example:
<============================================================
import CYPL.utils.EventDpMediator;
var ms=new EventDpMediator(stage);
ms.addEventListener(MouseEvent.MOUSE_DOWN,handler,{o:3});
ms.addEventListener(MouseEvent.MOUSE_UP,handler,4);
ms.addEventListener(MouseEvent.CLICK,handler);
//参数m:中介对象,e:事件对象,arg参数对象
function handler(m:EventDpMediator,e:Event,arg:*=null) {
switch (e.type) {
case MouseEvent.MOUSE_DOWN :
trace("MouseEvent.MOUSE_DOWN:",arg.o);
break;
case MouseEvent.MOUSE_UP :
trace("MouseEvent.MOUSE_UP",arg);
break;
case MouseEvent.CLICK :
trace("MouseEvent.CLICK:",arg);
break;
}
//handler内部可以通过第一个参数中介对象来remove
m.removeEventListener(MouseEvent.MOUSE_DOWN,handler);
}
//外部可以直接用中介对象来remove
ms.removeEventListener(MouseEvent.MOUSE_UP,handler);
===========================================================>
*/
转自http://www.iteye.com/topic/605088