English 中文(简体)
AS3 使儿童从事手工艺工作
原标题:AS3 to get children in Gestureworks TouchSprite working

Recently just trying around with the Gestureworks multitouch. Here I have some problem about button inside a TouchSprite, below is my code:

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;
        }
    }
}

显然我的Display.mouse children = true; 会让我的Display 无法拖动或缩放 。

问题回答

在添加您的大映射按钮之前, 将我的 Display 的鼠标儿童属性设定为真 :

我的Display.mouse children = true; 我的Display.mouse children = true; 我的Display.mouse children = true; 我的Display.mouse children = true; 我的Display.mouse children = true; 我的Display.mouse children = true; 我的Display.

这将将鼠标日传送到里面的对象 。

另外,根据您想要的效果(我假设这是多触摸的杂草屏幕),我建议您最好在大地图上使用触摸点。 TOUCH_TAP 而不是鼠标点。 CLICK(鼠标点不是多触摸点,如果屏幕的另一部分同时有某种触碰,就不会作出反应)。

编辑 :

假设boliviaMap和地图Pink不是触摸MovieClips或触摸Sprites,

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

然后加上孩子,假设boliviaMap和地图Pink小于500x500px:

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

编辑 2 - 一个工作范例( 对我来说, 无论如何) 将触摸节与 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");
        }
    }
}

我还要补充的是,这只对触发TeachEvents的屏幕/装置有效(如果你用鼠标点击我的TapableSprite,它不会触发事件)。





相关问题
Attaching a property to an event in Flex/AS3

I have a parameter that needs to be passed along with an event. After unsuccessful attempts to place it on the type by extending the class, I ve been advised in another SO question to write a custom ...

Sorting twodimensional Array in AS3

So, i have a two-dimensional Array of ID s and vote count - voteArray[i][0] = ID, voteArray[i][1] = vote count I want the top 3 voted items to be displayed in different colors, so i have a 2nd Array -...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

What s a good way of deserializing data into mock objects?

I m writing a mock backend service for my flex application. Because I will likely need to add/edit/modify the mock data over time, I d prefer not to generate the data in code like this: var mockData =...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

热门标签