2009-05-23 2 views
2

나는 Winforms와 WPF 모두에서 C# 프로그래밍을 많이 해왔다. 현재 크로스 플랫폼 지원을 위해 Flex/Air 앱을 개발하고 있습니다. 하지만 이것은 내 첫 번째 플렉스 프로젝트이므로, 제가 배우는대로 배우고 있습니다.플렉스 : 팝업 창 - [ok] 또는 [취소]

팝업 창이있어서 사용자가 양식을 작성한 다음 OK 또는 CANCEL을 누릅니다. C#에서와 같은 방식으로 설정했지만 작동하지 않으며 실제로 원하는대로 할 수있는 방법을 볼 수 없습니다.

편집 : 그래서 시도하고 이벤트가 이제 이벤트가 바로 처리하지 않는 것 ...

편집 다시는 : 아, 팝업 관리자의 새 인스턴스를 만들 것으로 보인다 있기 때문에 이미 만든 객체를 사용하는 대신 Form 객체를 사용합니다.

그래서이 ShowWindow 방법에, 나는 팝업 관리자 대신이 코드에 넣어 : 나는 그것을 닫을 때
parent.addChild(this); 

는 나는 그것을 제거합니다. 유일한 문제는 팝업 관리자처럼 부모의 나머지 부분을 사용 중지하지 않는다는 것입니다. 그것에 관한 어떤 제안?

부모 :

private function btnAdd_Clicked():void 
{    
     var form:Form = new Form(); 
     form.addEventListener(CloseEvent.CLOSE, onFormClosed, false, 0, true); 

     recipeForm.showWindow(this); 
} 

private function onFormClosed(e:CloseEvent):void 
{ 
    //none of these Alerts are ever shown. I also tried breakpoints in debug to try an follow the code, with no luck 
    Alert.show("Closed"); 
    if(e.detail == Alert.OK) 
    { 
     Alert.show("OK"); 
    } 
    else if(e.detail == Alert.CANCEL) 
    { 
     Alert.show("Cancel"); 
    } 
} 

아동 :

private function btnCancel_Clicked():void 
{ 
    okClicked = false; 
    closeWindow(); 
} 

public function closeWindow():void 
{ 
    var e:CloseEvent = new CloseEvent(CloseEvent.CLOSE); 
    e.detail = okClicked ? Alert.OK : Alert.CANCEL; 
    dispatchEvent(e); 
    PopUpManager.removePopUp(this); 
} 

public function showWindow(parent:WindowedApplication):void 
{ 
    var window:IFlexDisplayObject = PopUpManager.createPopUp(parent, RecipeForm, true); 
    PopUpManager.centerPopUp(window); 
} 

답변

3

당신은이 작업을 수행 할 수있는 적어도 두 가지 방법 :

첫 번째 방법 : 사용 이벤트

양식 클래스 파견하자 두 단추 중 하나를 클릭하면 이벤트. Form이 부모 뷰로부터 인스턴스화 된 후에 디스패치하는 것으로 알려진 이벤트에 대한 eventListener를 추가하십시오. Form이 이벤트를 전달하면 eventListener가 호출됩니다. Flex의 CloseEvent를 재사용하고 "detail"속성을 Alert.OK 또는 Alert.CANCEL로 설정하여 디스패치 할 수도 있습니다. 형태로

:

부모에
var e:CloseEvent = new CloseEvent(CloseEvent.CLOSE); 
e.detail = okClicked ? Alert.OK : Alert.CANCEL; 
dispatchEvent(e); 

:

var f:Form = new Form(); 
f.addEventListener(CloseEvent.CLOSE, onClose, false, 0, true); 
... 
private function onClose(e:CloseEvent):void 
{ 
    if (e.detail == Alert.OK) 
     // do something 
    else if (e.detail == Alert.CANCEL) 
     // do something else 
} 

두 번째 방법 : 사용 콜백

당신의 폼 클래스 타입 "기능"의 공개 VAR를 추가하고 콜백을 제공 함수를 부모로부터 가져옵니다. 이는 기본적으로 추상화/간접 지정이 거의없는 경우를 제외하고는 # 1과 동일합니다.

플렉스의 이벤트 모델이 콜백보다 꽤 잘 생각되고 융통성이 있기 때문에 # 1을 권합니다. 형태로

+0

이 보인다,하지만 사건은 그냥 ... 처리하지 않는 것 아이 : 공공 기능 closeWindow() : 무효 { \t VAR 전자 : CloseEvent = 새로운 CloseEvent (CloseEvent. 닫기); \t e.detail = okClicked? 알리. 알. 카셀; \t dispatchEvent (e); \t \t PopUpManager.removePopUp (this); } 상위 : btnAddRecipe_Clicked 개인 함수() {공백 \t \t \t \t \t VAR의 recipeForm : RecipeForm = 새로운 RecipeForm(); \t recipeForm.addEventListener (CloseEvent.CLOSE, onRecipeFormClosed, false, 0, true); \t \t recipeForm.showWindow (this); } 개인 기능 onRecipeFormClosed (예 : CloseEvent) : 는 { 가져 결코 // 무효가 여기에 도착 ... :/ } – Joel

+0

오, 코멘트 oopps ... 난거야 ... 줄 바꿈 허용하지 않습니다 그것을 원래 게시물로 편집하십시오. – Joel

+0

showWindow()가 RecipeForm 클래스의 새로운 인스턴스를 반환하는 것처럼 보입니다. 해당 클래스에 이벤트 리스너를 연결하려고합니다. 이벤트를 보낸 객체는 리스너가 등록 된 객체와 동일한 객체 여야합니다. –

1

:

var e:CloseEvent = new CloseEvent(CloseEvent.CLOSE); 
e.detail = okClicked ? Alert.OK : Alert.CANCEL; 
dispatchEvent(e); 

부모에서 :

var f:Form = new Form(); 
f.addEventListener(CloseEvent.CLOSE, onClose, false, 0, true); 
... 
private function onClose(e:CloseEvent):void 
{ 
    if (e.detail == Alert.OK) 
     // do something 
    else if (e.detail == Alert.CANCEL) 
     // do something else 
} 
0

이 여전히 열려있는 문제가 있는지 확실하지. 나는이 똑같은 문제에 부 닥쳤다. 나는 무엇이 잘못되었는지를 생각했다. 적어도 나는 내 문제를 해결했다.

정확하게 구현했습니다. 또한 closeWindow에 가까운 속성을 설정했습니다 (대화 상자에 TitleWindow를 사용하고 있습니다).

그래서 X가 맨 위에 닫히면 closeWindow가 호출되고 취소 버튼을 클릭하면 closeWindow도 호출됩니다. 나를 위해 문제가 클릭 취소, CloseWindow (아마도 자체 내부 수신기를 생성하는 닫는 특성을 통해) 호출하여 Listener에 의해 catch 된 것으로 보이는 CloseEvent를 발송했다. 나는 그것의 무한 루프가 아니라 Flex가 이것을 좋아하지 않을지 확신하지 못합니다.

내 솔루션은 X 닫기 창을 호출하고 취소 버튼을 사용하여 자체 CloseEvent를 전달하는 두 가지 기능을 만드는 것이 었습니다. 이것은 나를 위해 일하는 것 같았다. 희망이 당신을 돕는다. 그것은 작동해야처럼