最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
AS3中类似watch的功能
时间:2022-07-02 17:19:18 编辑:袖梨 来源:一聚教程网
/**
*
* @class:WO(.watch)
* @author:ycccc8202
* @date:2007.8.2
* @example:
* import com.ycccc.utils.WO;
* var mc:MovieClip=new MovieClip();
* var __mc:WO=new WO(mc);
* var arg:String="1234";
* __mc.watch("x",watchFunc);
* function watchFunc(p,o,n,a) {
* trace(arguments);
* return n;
* }
* __mc.x=99;
* __mc.x=100;
* __mc.watch("y",watchFunc,arg);
* __mc.y=101;
* __mc.y=102;
*
**/
package com.ycccc.utils{
import flash.utils.Proxy;
import flash.utils.flash_proxy;
public dynamic class WO extends Proxy {;
private var _obj:*;
private var _watchHashTable:Object;
/**Constructor WO
*
* @param obj:* 对象
*
**/
public function WO(obj:*) {
_watchHashTable={};
_obj=obj;
}
/**Public function watch
*
* @param prop:String 属性
* @param callBackFunc:Function 回调函数
* @param arg:*=null 可选参数
*
**/
public function watch(prop:String,callBackFunc:Function,arg:*=null):void {
_watchHashTable[prop]={};
_watchHashTable[prop].prop=prop;
_watchHashTable[prop].oldV=flash_proxy::getProperty(prop);
_watchHashTable[prop].newV=null;
_watchHashTable[prop].callBackFunc=callBackFunc;
_watchHashTable[prop].arg=arg;
}
override flash_proxy function callProperty(methodName:*, ... args):* {
return _obj[methodName].apply(_obj,args);
}
override flash_proxy function getProperty(name:*):* {
//trace("getProperty");
return _obj[name];
}
override flash_proxy function setProperty(name:*, value:*):void {
//trace("setProperty");
if (_watchHashTable[name]!=undefined && value!=_watchHashTable[name].oldV) {
_watchHashTable[name].newV=value;
_watchHashTable[name].oldV=_watchHashTable[name].callBackFunc.apply(null,[_watchHashTable[name].prop,_watchHashTable[name].oldV,_watchHashTable[name].newV,_watchHashTable[name].arg]);
}
_obj[name] = value;
}
}
}
var mc:MovieClip=new MovieClip();
var __mc:WO=new WO(mc);
var arg:String="1234";
__mc.watch("x",watchFunc);
function watchFunc(p,o,n,arg) {
trace(arguments);
return n;
}
__mc.x=99;
__mc.x=100;
__mc.watch("y",watchFunc,arg);
__mc.y=101;
__mc.y=102;
__mc.watch("z",watchFunc,arg);
__mc.z=88
__mc.z=99
相关文章
- 王者荣耀侦探能力大测试攻略 王者荣耀侦探能力大测试怎么过 11-22
- 无期迷途主线前瞻兑换码是什么 11-22
- 原神欧洛伦怎么培养 11-22
- 炉石传说网易云音乐联动怎么玩 11-22
- 永劫无间手游确幸转盘怎么样 11-22
- 无期迷途主线前瞻兑换码是什么 无期迷途主线前瞻直播兑换码介绍 11-22