簡體   English   中英

CreateJS事件到Javascript事件

[英]CreateJS Events to Javascript events

我將兩個畫布元素層疊在一起。 頂部的畫布用於UI,並使用createjs框架來實現它的魔力。

另一個canvas元素基於巴比倫js框架,以繪制一些3D魔術。

我的麻煩是各層之間的通信。 我在UI層上創建了一個不可見的矩形來捕獲鼠標事件,但是它們以CreateJS MouseEvents的形式出現,我需要將它們轉換為HTML版本,以分派到3D層上。

有人知道我需要什么代碼才能將createJS鼠標事件轉換為HTML鼠標事件嗎? (請不要使用jQuery)

這是haxe代碼中的想法(至少是真正重要的部分):

private function initialize()
{
    _blocker = new Shape();
    _blocker.graphics.beginFill("#000000");
    _blocker.graphics.drawRect(0, 0, Container3D.WIDTH, Container3D.HEIGHT);
    _blocker.graphics.endFill();
    _blocker.alpha = 0.01;

    _blocker.addDblclickEventListener(onEvent);
    _blocker.addClickEventListener(onEvent);
    _blocker.addMousedownEventListener(onEvent);
    _blocker.addMouseoutEventListener(onEvent);
    _blocker.addMouseoverEventListener(onEvent);
    _blocker.addPressmoveEventListener(onEvent);
    _blocker.addPressupEventListener(onEvent);
    _blocker.addRolloutEventListener(onEvent);
    _blocker.addRolloverEventListener(onEvent);
}

private function onEvent(e:MouseEvent):Void
{
    /* need to convert the createjs mousevent to an html mouseevent here */
//var htmlMouseEvent:js.html.MouseEvent = convertToHtmlEvent(e);
        // and dispatch it on the other canvas
        my3DCanvas.dispatchEvent(htmlMouseEvent);
}

private function converToHtmlEvent(evToConvert):js.html.MouseEvent
{
   // do magic here
}

謝謝。

CreateJS事件包含對觸發它們的本機事件的引用。

private function onEvent(e:MouseEvent):Void
{
    /* need to convert the createjs mousevent to an html mouseevent here */
//var htmlMouseEvent:js.html.MouseEvent = convertToHtmlEvent(e);
        // and dispatch it on the other canvas
        var htmlMouseEvent = e.nativeEvent;
        my3DCanvas.dispatchEvent(htmlMouseEvent);
}

這是文檔: http : //createjs.com/docs/easeljs/classes/MouseEvent.html#property_nativeEvent

希望有幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM