| Package | flash.utils |
| Class | public class Proxy |
| Inheritance | Proxy Object |
| Subclasses | AbstractService , DescribeTypeCacheRecord , ListCollectionView , ObjectProxy |
Proxy 클래스에는 constructor 이 없기 때문에, Proxy 를 초기화하지 말아 주세요. 대신에, Proxy 클래스를 서브 클래스화해 getProperty 등의 Methods를 덧쓰기해, custom 행동을 지정합니다. Methods를 덧쓰기하지 않고 Proxy 클래스의 Methods를 사용하려고 하면, 예외가 발생합니다.
또, Proxy 클래스의 Methods를 덧쓰기하는 독자적인 코드에 의해, 의도하지 않는 형태로 예외가 슬로우 되는 경우가 있습니다. 이러한 Methods의 사용시에 예외가 슬로우 되면, (in,is,delete등의 연산자를 사용한다) 호출원코드로 예외가 예기되어 있지 않기 때문에, 문제가 발생합니다. Methods의 덧쓰기에 의해 예외가 슬로우 되지 않는 것을 확인하지 않는 한, 연산자에 의해 Methods를 호출할 때에 값명적인 에러가 발생하는 것을 피하기 (위해)때문에, Proxy 클래스의 Implements에는 try..catch 명령문(statement)를 사용하는 것을 추천합니다. 다음에 예를 나타냅니다.
dynamic class MyProxy extends Proxy {
flash_proxy override function callProperty(name:*, ...rest):* {
try {
// custom code here
}
catch (e:Error) {
// respond to error here
}
}
Proxy 클래스는 ActionScript 2.0 의 Object. __resolve 및 Object.addProperty 기능의 후계입니다. 이러한 기능은, ActionScript 3.0 에서는 사용할 수 없게 됩니다. Object.addProperty() 기능을 사용하면, ActionScript 2.0 의 get 및 set Methods를 동적으로 작성할 수 있습니다. ActionScript 3.0 에서는, 컴파일시에 get 및 set Methods가 제공됩니다만, Proxy 클래스를 사용하지 않는 경우는 object에 동적으로 할당할 수가 없습니다.
public namespace의 경합을 피하기 위해서(때문에), Proxy 클래스의 Methods는 flash_proxy namespace에 있습니다.
Proxy 클래스의 Methods가 name 인수를 취하는 경우는,name 는 String object 또는 QName object의 어느 쪽인가에 할 수가 있습니다.
| Methods | 정의 | ||
|---|---|---|---|
| callProperty (name:* , ... rest):*
함수로서 호출해 가능한 object property의 동작을 덧쓰기합니다.
| Proxy | ||
| deleteProperty (name:* ):Boolean
property를 삭제하는 요구를 덧쓰기합니다.
| Proxy | ||
getDescendants (name:* ):*
descendant 연산자의 사용을 재정의(override) 합니다. | Proxy | ||
| getProperty (name:* ):*
property의 값에 대한 요구를 덧쓰기합니다.
| Proxy | ||
| hasProperty (name:* ):Boolean
object가 특정의 property를 가지고 있을지 어떨지를 이름 마다 체크하는 요구를 덧쓰기합니다.
| Proxy | ||
| isAttribute (name:* ):Boolean
지정된 QName 가 속성으로서 마크 되고 있는지 어떤지를 확인합니다.
| Proxy | ||
| nextName (index:int ):String
인덱스 번호를 사용해, 프록시가 되는 object의 property를 열거해 property명을 취득할 수 있습니다.
| Proxy | ||
| nextNameIndex (index:int ):int
인덱스 번호를 사용해, 프록시가 되는 object의 property를 열거할 수 있습니다.
| Proxy | ||
| nextValue (index:int ):*
인덱스 번호를 사용해, 프록시가 되는 object의 property를 열거해 property치를 취득할 수 있습니다.
| Proxy | ||
| setProperty (name:* , value:* ):void
property의 값을 변경하는 호출을 덧쓰기합니다.
| Proxy | ||
| callProperty | () | Methods |
flash_proxy function callProperty(name:* , ... rest):* 함수로서 호출해 가능한 object property의 동작을 덧쓰기합니다. object의 Methods가 불려 갈 때, 이 Methods가 불려 갑니다. 함수로서 호출해 가능한 object도 있습니다만, 함수로서 호출해 가능한 object property도 있습니다.
Parametersname:* — 불려 가는 Methods의 이름입니다.
|
|
... rest — 불려 가는 Methods에 인수를 지정하는 배열입니다.
|
* — 호출한 Methods의 반환값입니다.
|
See also
| deleteProperty | () | Methods |
flash_proxy function deleteProperty(name:* ):Boolean
property를 삭제하는 요구를 덧쓰기합니다. property가 delete 조작으로 삭제되면, 이 Methods가 불려 가 삭제가 실행됩니다.
name:* — 삭제하는 property의 이름입니다.
|
Boolean —
property가 삭제되었을 경우는 true, 그 이외는 false 를 돌려줍니다.
|
See also
| getDescendants | () | Methods |
flash_proxy function getDescendants(name:* ):*
descendant 연산자의 사용을 재정의(override) 합니다. descendant 연산자가 사용되면, 이 Methods가 불려 갑니다.
name:* — object에 Inheritance하는 검색 대상의 property의 이름입니다.
|
* — descendant 연산자의 결과입니다.
|
See also
| getProperty | () | Methods |
flash_proxy function getProperty(name:* ):*
property의 값에 대한 요구를 덧쓰기합니다. property가 발견되지 않았던 경우, 이 Methods는 undefined 를 돌려줍니다. 이 동작의 상세한 것에 대하여는, ECMA-262 언어 사양 Edition 3 의 섹션 8.6. 2.1 을 참조해 주세요.
name:* — 취득하는 property의 이름입니다.
|
* — property가 발견되지 않았던 경우, 지정된 property 또는 undefined 가 돌려주어집니다.
|
See also
| hasProperty | () | Methods |
flash_proxy function hasProperty(name:* ):Boolean object가 특정의 property를 가지고 있을지 어떨지를 이름 마다 체크하는 요구를 덧쓰기합니다.
Parametersname:* — 체크하는 property의 이름을 나타냅니다.
|
Boolean —
Parameters가 존재하는 경우는 true, 그 이외는 false 를 돌려줍니다.
|
See also
| isAttribute | () | Methods |
flash_proxy function isAttribute(name:* ):Boolean 지정된 QName 가 속성으로서 마크 되고 있는지 어떤지를 확인합니다.
Parametersname:* — 체크하는 property의 이름입니다.
|
Boolean —
속성으로서 마크 되고 있는 QName 가 name 의 속성인 경우,true 를 돌려줍니다.
|
See also
| nextName | () | Methods |
flash_proxy function nextName(index:int ):String
인덱스 번호를 사용해, 프록시가 되는 object의 property를 열거해 property명을 취득할 수 있습니다. 다만, Proxy 클래스 자신의 property를 열거할 수 없습니다. 이 함수에서는, 목적의 이름을 취득하기 위해서, object에 대한 for...in 및 for each..in 루프의 Implements이 지원(support)되고 있습니다.
예 (Proxy.nextNameIndex() 의 코드):
protected var _item:Array; // array of object's properties
override flash_proxy function nextNameIndex (index:int) :int {
// initial call
if (index == 0) {
_item = new Array();
for (var x:* in _target) {
_item.push(x);
}
}
if (index < _item.length) {
return index + 1;
} else {
return 0;
}
}
override flash_proxy function nextName(index:int) :String {
return _item[index - 1];
}
index:int — object의 property를 나타내는 0 으로부터 시작되는 인덱스치입니다.
|
String —
String - property의 이름입니다.
|
See also
| nextNameIndex | () | Methods |
flash_proxy function nextNameIndex(index:int ):int
인덱스 번호를 사용해, 프록시가 되는 object의 property를 열거할 수 있습니다. 다만, Proxy 클래스 자신의 property를 열거할 수 없습니다. 이 함수에서는, property의 인덱스치를 취득하기 위해서, object에 대한 for...in 및 for each..in 루프의 Implements이 지원(support)되고 있습니다.
다음에 예를 나타냅니다.
protected var _item:Array; // array of object's properties
override flash_proxy function nextNameIndex (index:int) :int {
// initial call
if (index == 0) {
_item = new Array();
for (var x:* in _target) {
_item.push(x);
}
}
if (index < _item.length) {
return index + 1;
} else {
return 0;
}
}
override flash_proxy function nextName(index:int) :String {
return _item[index - 1];
}
index:int — 열거의 개시를 나타내는 0 으로부터 시작되는 인덱스치입니다.
|
int —
property의 인덱스치입니다.
|
See also
| nextValue | () | Methods |
flash_proxy function nextValue(index:int ):*
인덱스 번호를 사용해, 프록시가 되는 object의 property를 열거해 property치를 취득할 수 있습니다. 다만, Proxy 클래스 자신의 property를 열거할 수 없습니다. 이 함수에서는, 목적의 값을 취득하기 위해서, object에 대한 for...in 및 for each..in 루프의 Implements이 지원(support)되고 있습니다.
예 (Proxy.nextNameIndex() 의 코드):
protected var _item:Array; // array of object's properties
override flash_proxy function nextNameIndex (index:int) :int {
// initial call
if (index == 0) {
_item = new Array();
for (var x:* in _target) {
_item.push(x);
}
}
if (index < _item.length) {
return index + 1;
} else {
return 0;
}
}
override flash_proxy function nextName(index:int) :String {
return _item[index - 1];
}
index:int — object의 property를 나타내는 0 으로부터 시작되는 인덱스치입니다.
|
* — property의 값입니다.
|
See also
| setProperty | () | Methods |
flash_proxy function setProperty(name:* , value:* ):void property의 값을 변경하는 호출을 덧쓰기합니다. property가 발견되지 않았던 경우, 이 Methods는, 지정된 이름 및 값을 사용해 property를 작성합니다.
Parametersname:* — 변경하는 property의 이름입니다.
|
|
value:* — property로 설정하는 값입니다.
|
See also
package {
import flash.display.Sprite;
public class ProxyExample extends Sprite {
public function ProxyExample() {
var arr:ProxyArray = new ProxyArray();
arr.push(1);
arr.push(-2);
arr.push(3);
arr.push(4);
arr.push("five");
trace(arr.length); // 5
trace(arr[0]); // 1
trace(arr[1]); // -2
trace(arr[2]); // 3
trace(arr[3]); // 4
trace(arr.sum()); // 6
arr.clear();
trace(arr); // (empty string)
arr[0] = "zero";
trace(arr); // zero
}
}
}
import flash.utils.Proxy;
import flash.utils.flash_proxy;
dynamic class ProxyArray extends Proxy {
private var _item:Array;
public function ProxyArray() {
_item = new Array();
}
override flash_proxy function callProperty(methodName:*, ... args):* {
var res:*;
switch (methodName.toString()) {
case 'clear':
_item = new Array();
break;
case 'sum':
var sum:Number = 0;
for each (var i:* in _item) {
// ignore non-numeric values
if (! isNaN(i)) {
sum += i;
}
}
res = sum;
break;
default:
res = _item[methodName]. apply(_item, args);
break;
}
return res;
}
override flash_proxy function getProperty(name:*):* {
return _item[name];
}
override flash_proxy function setProperty(name:*, value:*) :void {
_item[name] = value;
}
}
코멘트가 추가되었을 경우, 메일로 받기. | 코멘트 리포트
현재의 페이지: http://flexdocs.kr/docs/flex2/langref/flash/utils/Proxy.html