본문 바로가기

인사이드RIA/인사이드플렉스

플렉스 모듈 사용시 1034 오류에 대한 대처

반응형
플렉스 모듈 사용시 Alert 처리시 1034 오류가 발생하는 경우가 있습니다.
이전에 올라온 글들을 검색하면 뷰스택을 쓰면서 충돌이 생긴다고 하는데
그건 아닌것 같고 매니저 관련 클래스와 관련된 처리시 문제가 생깁니다.
(아마 뷰스택과 같이 사용되면서 발견된 현상이 전파되면서 그렇게 인식이 된것 같습니다).

TypeError: Error #1034: 유형 강제 변환에 실패했습니다.
mx.managers::PopUpManagerImpl@7809161을(를)
mx.managers.IPopUpManager(으)로 변환할 수 없습니다.

이미 플렉스 버그로 올라왔지만
버그는 아니다...라고 결론이 났네요.
https://bugs.adobe.com/jira/browse/SDK-16474

문제가 생긴 상황은 다음과 같습니다.
버그 리포팅이 되기 전에 이 내용이 있었는지는 모르겠네요.
하여간 플렉스 4 문서에도 아래와 같이 동일한 내용이 올라와 있습니다.

By default, a module is loaded into a child domain of the current application domain. You can specify a different application domain by using the applicationDomain property of the ModuleLoader class.  Because a module is loaded into a child domain, it owns class definitions that are not in the main application’s domain. For example, the first module to load the PopUpManager class becomes the owner of the PopUpManager class for the entire application because it registers the manager with the SingletonManager. If another module later tries to use the PopUpManager, Adobe ® Flash® Player throws an exception.
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-799a.html

어플리케이션 도메인에 대한 내용은 아래를 참고하세요.
Flex 모듈 프로그래밍의 기초 - Application domain의 이해 1부
http://blog.jidolstar.com/345

뭐 하여간 결론은 개발자들이 알아서
해당 이슈가 생기지 않도록 하는 겁니다.
메인 어플리케이션쪽에 다음과 같이 방어적인 선언을 해주면
문제를 해결할 수 있습니다.
(위에 링크된 도움말 문서에도 나와있는 내용이지만 좀 더 깔끔하게 정리가 되었네요).

import mx.managers.PopUpManager;
import mx.managers.DragManager;
import mx.managers.HistoryManager; 

private var _linkage:Array = [PopUpManager, DragManager, HistoryManager];

이 내용을 좀 더 집요하게 설명한 글이 있습니다.
더 궁금하시다면 참조..
Beware of singleton in Flex modules
http://www.devahead.com/blog/2010/03/beware-of-singleton-in-flex-modules/
728x90