2015-12-21 38 views
1

我是新來的as3,我需要做一件非常簡單的事情。我有以下代碼,它工作得很好。但我需要什麼,不能弄清楚如何做到這一點是:如何在as3的MOUSE_DOWN上使用不同的鼠標光標?

  1. 改變鼠標光標,當我拿着鼠標中鍵(從符號選擇)
  2. 與它(移動通常會消失時能力我用鼠標移動)

    import flash.display.Sprite; 
        import flash.events.Event; 
        import flash.events.MouseEvent; 
        import fl.motion.MotionEvent; 
    
        var CursorStill: Sprite; 
        var CursorAnim: Sprite; 
    
        function init() { 
         Mouse.hide(); 
    
         CursorStill = new CursorStillClass(); 
         CursorStill.mouseEnabled = false; 
         CursorStill.visible = false; 
    
         addChild(CursorStill); 
    
         stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler); 
         stage.addEventListener(Event.MOUSE_LEAVE, mouseLeaveHandler); 
         stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler); 
        } 
    
        function mouseMoveHandler(evt: MouseEvent): void { 
         CursorStill.visible = true; 
         CursorStill.x = evt.stageX; 
         CursorStill.y = evt.stageY; 
         evt.updateAfterEvent(); 
        } 
    
        function mouseLeaveHandler(evt: Event): void { 
         CursorStill.visible = false; 
    
        } 
    
        function mouseDownHandler (evt: MouseEvent): void { 
         CursorStill.visible = false; 
        } 
    
        init(); 
    

回答

0

我的一個朋友幫我,我理解了它。我希望這將幫助其他新手至少:)

import flash.events.Event; 
import flash.events.MouseEvent; 
import fl.motion.MotionEvent; 

function init() { 
    Mouse.hide(); 

    // this creates an instance of the library MovieClip with the 
    // name, "MyCursorClass". this contains your mouse cursor art 
    // 
    Cursor = new CursorClass(); 
    Cursor.mouseEnabled = false; 
    Cursor.visible = false; 

    // you'll want to make sure the child is added above everything 
    // else, possibly in its own container 
    // 
    addChild(Cursor); 

    // respond to mouse move events 
    stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler); 
    stage.addEventListener(Event.MOUSE_LEAVE, mouseLeaveHandler); 
    stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler); 
    stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler); 
} 

function mouseMoveHandler(evt: MouseEvent): void { 
    // whenever the mouse moves, place the cursor in the same spot 
    Cursor.visible = true; 
    Cursor.x = evt.stageX; 
    Cursor.y = evt.stageY; 
    // for smoother mouse pointer 
    evt.updateAfterEvent(); 
} 

function mouseLeaveHandler(evt: Event): void { 
    Cursor.visible = false; 

} 

function mouseDownHandler(evt: MouseEvent): void { 
    Cursor.gotoAndStop(xx); 
} 

function mouseUpHandler(evt: MouseEvent): void { 
    Cursor.gotoAndStop(xx); 
} 

init(); 

最學分轉到本教程雖然

http://danielmclaren.com/2008/03/tips-for-using-custom-mouse-cursors-in-flash-as3