分类:
2010-09-27 15:11:42
1.功能解析
这个类比Observe 类多了一个value
重载了方法callHandler(),并给出下面代码
if (source != value)
return;
说明:当value与观察对象不一致时,直接返回,并不调用函数处理器。为什么?
2.程序解析
package com.adobe.cairngorm.observer
{
public class ObserveValue extends Observer
{
//是否将value初始化,作用未知
private var
isValueInitialized:Boolean = false;
//函数处理器
private var _handler:Function;
//观察对象
private var _source:Object;
//未知
private var _value:Object;
//构造函数
public function ObserveValue()
{
sendArgumentsToHandler = false;
}
//函数处理器的get方法
override public function get
handler():Function
{
return
_handler;
}
//设置函数处理器
public function set
handler(value:Function):void
{
_handler =
value;
if (value !=
null)
{
//如果存在函数处理器,则设置isHandlerInitialized 为真
isHandlerInitialized = true;
if (isHandlerInitialized && isSourceInitialized &&
isValueInitialized)
{
callHandler();
}
}
}
//观察对象的get方法
override public function get
source():Object
{
return
_source;
}
//设置观察对象
public function set
source(value:Object):void
{
_source =
value;
//如果存在观察对象,isSourceInitialized
为真
isSourceInitialized
= true;
if
(isHandlerInitialized && isSourceInitialized &&
isValueInitialized)
{
callHandler();
}
}
public function get value():Object
{
return
_value;
}
public function set
value(_value:Object):void
{
this._value
= _value;
//如果存在观察对象,isValueInitialized
为真
isValueInitialized = true;
if
(isHandlerInitialized && isSourceInitialized &&
isValueInitialized)
{
callHandler();
}
}
//重载了callHandler方法
override protected function
callHandler():void
{
if (source
!= value)
return;
try
{
callHandlerWithArguments();
}
catch
(e:Error)
{
delay(e);
}
}
}
}