플래시 자체가 이벤트 기반의 프로그램이다 보니 발생하는 이벤트 중심으로 코딩하는 방법이 로직상이나 가독성 측면에서 좋은 코딩 방법이라는 생각이 든다.
하지만 이벤트 별로 패턴을 나누다 보니 코드길이가 자연스레 길어지고 이벤트 리스너(addEventListener) 를 연결하는 시간과 인스턴스를 초기화하는 시간과의 차이로 인해 적지않은 문제점이 발생한다.
var myLoader:XmlLoader=new XmlLoader(this,UrlSet.xmlUrl+"navigation.xml",100,100);
myLoader.setXmlAttribute(["label","src","loadingPos"]);
myLoader.addEventListener(XmlLoaderEvent.ON_START,this);
function onStart(evt:XmlLoaderEvent){
myLoader.removeEventListener(XmlLoaderEvent.ON_START);
//파싱완료후 실행함수}
간혹가다 인스턴스(myLoader ) 초기화보다 인스턴스 메소드가 먼저 실행되는 이상한 일이 발생할 경우가 있다.
In ActionScript 2.0, type annotations were primarily a developer aid; at runtime, all values were dynamically typed. In ActionScript 3.0, type information is preserved at runtime, and utilized for a number of purposes. The Flash Player performs runtime type checking, improving the system’s type safety. Type information is also used to represent variables in native machine representations, improving performance and reducing memory usage.
단순히 개발자의 코드 가독성을 위한 도구였던 데이타 타입 설정이 As3.0 에서는 진정한 데이타 타입으로서 기능하게 되었다. 컴파일 타임에서의 데이타 타입의 체크에서 끝났던 것이 이제는 런타임에서도 타입체크가 가능하다.
이로써 실시간 예외처리도 가능해졌다. 플래시에서 가능 취약했던 부분인 런타임 디버깅이 비약적으로 발전했다. 이제보니 플래시가 스크립트 언어라고 하기엔 너무 커진것 같다는 생각이 든다..^^
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:
B(u) = P0 * ( 1 – u ) 2 + P1 * 2 * u ( 1 – u ) + P2 u2
을 이용하면 단순히 베지에 곡선을 그리는 것으로 끝나는 것이 아니라 각 포인트를 추적할 수 있다.
플래시에서 제공하는 curveTo 메서드도 물론 위 공식에 의한 계산으로 곡선을 그리는 것이지만 그리는것 이상의 것은 할 수 없었다.
function bezierPoint(mc:MovieClip,t:Number){var x = (1 - t )*(1 - t )* mc.p1._x + 2* t *(1 - t )* mc.p2._x + t * t * mc.p3._x;
var y = (1 - t )*(1 - t )* mc.p1._y + 2* t *(1 - t )* mc.p2._y + t * t * mc.p3._y;
mc.point_mc._x=x;
mc.point_mc._y=y;
}
control point 와 anchor point 를 지정해 곡선을 그리고 더 나아가 그린 곡선위의 포인트를 계산에 의해 추적이 가능하다. 즉, 스크립트로 모션이 가능하다.
Recent Comments