使用动作脚本 3 在 Flash Pro CS6 中移动触摸"tap"事件,一旦我测试电影,就会出现错误



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

如果我在已发布的电影中单击,代码将执行,但是当我通过 AIR Mobile 调试启动器中的触摸设置对其进行测试时,它会立即让我遵循

错误"类型错误:

错误 #1034:类型强制失败:无法将 flash.events::TouchEvent@5fe2ec1 转换为 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++;
}

}

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

为您的点击卡提供触摸事件:

并为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 播放器的非调试版本中运行? 也许吧。

最新更新