【问题标题】:Mobile touch "tap" event in flash pro CS6 using action script 3, keeps giving error as soon as I test the movie使用动作脚本3在flash pro CS6中移动触摸“点击”事件,在我测试电影时不断给出错误
【发布时间】:2013-10-07 02:05:21
【问题描述】:

我需要以下代码的帮助,我想添加移动触摸点击事件。我已经通过代码 sn-ps 面板添加了代码。

如果我在已发布的电影中单击,代码会执行,但一旦我通过 AIR Mobile 调试启动器中的触摸设置对其进行测试,它就会给我以下错误

“TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::TouchEvent@5fe2ec1 to flash.events.MouseEvent.”......

// create all the cards, position them, and assign a randomcard face to each
for(var xx:uint=0;xx<boardWidth;xx++) { // horizontal
    for(var yy:uint=0;yy<boardHeight;yy++) { // vertical
    var c:card = new card(); // copy the movie clip card
    c.stop(); // stop on first frame
    c.x = xx*cardHorizontalSpacing+boardOffsetX; // set position
    c.y = yy*cardVerticalSpacing+boardOffsetY;
    var r:uint = Math.floor(Math.random()*cardList.length); // get a random face
    c.cardface = cardList[r]; // assign face to card
    cardList.splice(r,1); // remove face from list
    Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
    c.addEventListener(TouchEvent.TOUCH_TAP, clickCard);
    c.addEventListener(MouseEvent.CLICK,clickCard); // have it listen for clicks
    trace(c.name);
    addChild(c); // show the card
    cardsLeft++;
}

}

【问题讨论】:

    标签: flash mobile touch-event


    【解决方案1】:

    不要对鼠标事件和触摸事件使用相同的事件处理程序。

    给你的 clickCard 一个 TouchEvent:

    并为 mouseEvents 创建一个新函数,因为鼠标事件的事件处理程序应该具有 MouseEvent 类型

    private function touchCard(e:TouchEvent):void
    {
        // all touches
        const touches:Vector.<Touch> = e.getTouches(_q);
        // phase ending (finger release)?
        for each (var touch:Touch in touches)
        {
            if (touch.phase == TouchPhase.ENDED)
            {
                trace("Touch ended on card!");
            }
        }
    }
    
    private function clickCard(e:MouseEvent):void
    {
        .. do stuff for mouses
    }
    

    显然更改代码中的处理程序以指向这些。

    发布时看不到错误的原因可能是因为发布电影可能设置为在非调试版本的 Flash 播放器中运行?也许吧。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多