2017-02-02 7 views
1

나는 마우스를 이동 한 경우에 감지 여기 AS3 클래스가 있습니다AS3와 플렉스 4 - 플렉스 MXML 파일에 적용 AS3 클래스

package 
{ 
    import flash.display.Sprite; 
    import flash.events.MouseEvent; 

    public class ApplicationTimer extends Sprite 
    { 

     public function ApplicationTimer() 
     { 
      stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoved); 
     } 

     public function mouseMoved(event:MouseEvent):void 
     { 
      trace("mouse moved") 
     } 

    } 
} 

는 내가 뭘하려고이 클래스 내 주요 MXML 플렉스를 적용입니다 그래서 내 마우스가 내 프로젝트에서 움직일 때 mouseMoved 메소드가 호출됩니다. 어떻게하면 좋을까요?

답변

3

MXML 파일은 이미 클래스이므로 스크립트를 추가 할 수 있습니다. MXML은 flex 구조를 사용하고 MXML 구성 요소는 Sprite가 아닌 UIComponent를 확장해야하므로 클래스를 직접 사용할 수 없습니다.

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" 
       mouseMove="mouseMoveHandler(event)"> 

    <fx:Script> 
     <![CDATA[ 
      protected function mouseMoveHandler(event:MouseEvent):void 
      { 
       trace(event); 
      } 
     ]]> 
    </fx:Script> 

    <fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
    </fx:Declarations> 
</s:Application>