Event handling is simplified in ActionScript 3.0 thanks to its built-in delegation. In ActionScript 2.0, method closures would not remember what object instance they were extracted from, leading to unexpected behavior when the method closure was invoked. The mx.utils.Delegate class was a popular workaround; to use it, you would write code as follows:
myButton.addEventListener(“click”, Delegate.create(this, someMethod));
This class is no longer needed, since a method closure will now automatically remember its original object instance. Now, one can simply write:
myButton.addEventListener(“click”, someMethod);
꼭 바뀌었으면 하는 것이 AS3.0 에서 개선되었다. AS2.0 에서는 중첩된 메서드에서 부모 오브젝트에 접근하지 못했다. 그래서 지역변수를 이용하거나 mx.utils.Delegate 클래스를 사용해 오브젝트 스코프를 지정했는데 이젠…이런게 필요없다.
자동으로 오브젝트를 기억한다고 한다…앞으론 좀더 코드가 간결해질듯 싶다.^^
0 Responses to “Delegation in AS3.0”