레이블이 event인 게시물을 표시합니다. 모든 게시물 표시
레이블이 event인 게시물을 표시합니다. 모든 게시물 표시

2009년 8월 16일 일요일

event 나중에 처리하기

flexmdi라는 flex에 데스크탑을 구현한 오픈소스가 있다. 여기를 클릭하면 볼 수 있다. 여기 샘플 코드에 괜찮은 설명이 있어서 옮겨 적는다.

 

 

   // the flex framework dispatches all kinds of events
   // in order to avoid catching one of those and throwing a coercion error
   // have your listener accept Event and check the type inside the function
   // this is good practice for all Flex development, not specific to flexmdi
   private function confirmWindowClose(event:Event):void
   {
    if(event is MDIManagerEvent && confirmCloseCb.selected)
    {
     // store a copy of the event in case we want to resume later (user confirms their intention)
     queuedEvent = event.clone() as MDIManagerEvent;
     
     // this is the line that prevents the default behavior from executing as usual
     // because the default handler checks event.isDefaultPrevented()
     event.preventDefault();
     
     Alert.show("Seriously? Close it?", null, 3, null, handleAlertResponse);
    }
   }
   
   // called when the Alert window is closed
   // if the user said yes, we execute the default behavior of playing an effect
   // and then removing the window by sending the stored event to
   // the appropriately named executeDefaultBehavior() method
   private function handleAlertResponse(event:CloseEvent):void
   {
    if(event.detail == mx.controls.Alert.YES)
    {
     mdiCanvas.windowManager.executeDefaultBehavior(queuedEvent);
    }
   }

 

 

윈도우를 닫을 때 발생한 이벤트에서 이벤트를 clone하여 queuedEvent라는 곳에 임시 저장하고 event는 preventDefault() 한다. 만약 사용자가 윈도우를 닫기 원하면 queuedEvent를 처리한다.

 

이벤트를 받을 때 타입체크를 하라는 설명도 보인다.

2009년 7월 22일 수요일

doubleClick 이벤트 받기

doubleClick 이라는 속성이 보이길래 이벤트 핸들러를 걸었겄만 이벤트가 발생하지 않았다. doubleClickEnabled 도 보이길래 true로 줬더니 그제사 이벤트가 발생핬다.

2009년 6월 8일 월요일

flexunit으로 event 테스트하기

1. 테스터를 만들때 TestCase 대신 EventfulTestCase를 상속받는다.

2. listenForEvent(이벤트Dispatcher, 이벤트타입, 발생할 것으로 예상하면 true 아니면 false);

3. dispatchEvent()

4. assertEvents(); 하면 2번에서 기대한 이벤트가 3번을 통해 발생됐는지 확인된다. 만약 2번에서 3번째 인자를 false로 했는데 이벤트가 감지되면 테스트가 실패한다.

 

연습삼아 해봤다. 별로 쓸모 없지만 custom event 자체를 테스트 해보려고 EventfulTestCase에서 IEventDispatcher를 구현하고 필요한 메소드들을 오버라이드 했다. 이벤트 발생시 이벤트를 통해 넘어온 값들을 바꾸고 테스트 쪽에서 해당 값이 잘 들어왔는지 assertEquals 테스트도 해봤다.