1

最近刚刚尝试使用 Gestureworks 多点触控。在这里,我对 TouchSprite 中的按钮有一些问题,下面是我的代码:

package 
{
    import com.gestureworks.core.GestureWorks;
    import com.gestureworks.core.TouchSprite;
    import com.gestureworks.events.GWGestureEvent;
    import com.gestureworks.events.GWTouchEvent;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Loader;
    import flash.display.Stage;
    import flash.events.Event;
    import flash.display.Sprite;
    import flash.net.URLRequest;
    import flash.events.MouseEvent;
    import flash.events.TouchEvent;
    import flash.ui.Multitouch;
    import flash.ui.MultitouchInputMode;

    public class Main extends GestureWorks
    {
        private var myDisplay:TouchSprite;

        public function Main():void
        {
            super();

            key = "xxx";

            Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
        }

        override protected function gestureworksInit():void
        {
            myDisplay = new TouchSprite();

            myDisplay.gestureReleaseInertia = true;
            myDisplay.gestureEvents = true;
            myDisplay.disableNativeTransform = false;
            myDisplay.disableAffineTransform = false;
            myDisplay.mouseChildren = true;
            myDisplay.gestureList = {"n-drag":true,"n-scale":true};

            myDisplay.addChild(boliviaMap);
            myDisplay.addChild(mapPink);
            addChild(myDisplay);

            myDisplay.addEventListener(GWGestureEvent.DRAG, gestureDragHandler);
            myDisplay.addEventListener(GWGestureEvent.SWIPE, gestureSwipeHandler);
            mapPink.addEventListener(TouchEvent.TOUCH_TAP, tapPink);
        }

        private function tapPink(e:TouchEvent):void
        {
            trace("PINK");
            indicatorTxt.text = "PINK";
        }

        private function gestureDragHandler(event:GWGestureEvent):void
        {
            trace("g drag: ", event.value.dx, event.value.dy);
            event.target.$x +=  event.value.dx;
            event.target.$y +=  event.value.dy;
            indicatorTxt.text = "g drag: " + event.value.dx + " " + event.value.dy;
        }
    }
}

显然 myDisplay.mouseChildren = true; 将使 myDisplay 无法再拖动或缩放。

4

1 回答 1

0

在添加 bigMap 按钮之前,请将 myDisplay 的 mouseChildren 属性设置为 true:

myDisplay.mouseChildren = true;

这应该将 mouseEvents 传递给内部的对象。

另外,根据您想要的效果(我假设这是用于某种多点触控屏幕),我建议您可能应该在 bigMap 上使用 TouchEvent.TOUCH_TAP 而不是 MouseEvent.CLICK(MouseEvents arent multi-touch如果同时在屏幕的另一部分有某种触摸,则不会响应)。

编辑:

假设 boliviaMap 和 mapPink 不是 TouchMovieClips 或 TouchSprites 然后做这样的事情:

myDisplay.graphics.beginFill(0x555555, 1);  
myDisplay.graphics.drawRect(0,0,500,500);
myDisplay.graphics.endFill();

然后添加您的孩子,假设 boliviaMap 和 mapPink 小于 500x500px:

myDisplay.addChild(boliviaMap);
myDisplay.addChild(mapPink);

编辑 2- 将 TouchEvents 与 GWEvents 相结合的工作示例(无论如何对我来说):

package  {

    import flash.display.MovieClip;
    import com.gestureworks.core.GestureWorks;
    import flash.ui.Multitouch;
    import flash.ui.MultitouchInputMode;
    import com.gestureworks.core.TouchSprite;
    import flash.display.Sprite;
    import flash.events.TouchEvent;

    public class Main extends GestureWorks {

        public function Main() {
            super(); 
            key = "INSERT YOUR GW KEY HERE";
            Multitouch.inputMode=MultitouchInputMode.TOUCH_POINT;
        }

        override protected function gestureworksInit():void 
        {
            trace("GestureWorks has initialized");
            var myTouchSprite:TouchSprite = new TouchSprite();
            myTouchSprite.graphics.beginFill(0x555555,1);
            myTouchSprite.graphics.drawRect(0,0,100,100);
            myTouchSprite.graphics.endFill();
            myTouchSprite.gestureReleaseInertia = false;
            myTouchSprite.gestureEvents = true;
            myTouchSprite.disableNativeTransform = false; 
            myTouchSprite.disableAffineTransform = false;
            myTouchSprite.gestureList = {"n-drag":true, "n-rotate":true};   
            myTouchSprite.mouseChildren = true;

            var myTappableSprite:Sprite = new Sprite();
            myTappableSprite.graphics.beginFill(0xAD3059,1);
            myTappableSprite.graphics.drawRect(30,30,40,40);
            myTappableSprite.graphics.endFill();
            myTappableSprite.addEventListener(TouchEvent.TOUCH_TAP, tappedThis);

            //myTouchSprite.addChild(myTappableSprite);
            myTouchSprite.addChild(myTappableSprite);
            addChild(myTouchSprite);
        }

        public function tappedThis(event:TouchEvent){
            trace("You tapped this");
        }
    }
}

我还应该补充一点,这仅适用于触发 TouchEvents 的屏幕/设备(如果您使用鼠标单击 myTappableSprite,则不会触发该事件)。

于 2012-05-24T15:54:09.673 回答