简体   繁体   English

SWFLoader 上的 Actionscript 3 和 Flex 4 缩放手势

[英]Actionscript 3 and Flex 4 Zoom Gesture on SWFLoader

I seem to be having issue with Zoom Gestures on a SWFLoader.我似乎对 SWFLoader 上的缩放手势有问题。 I have an swf file which is a floor plan of a home, I want the user to be able to zoom in and out with two finger touch, the following code below is what I tried and does not work.我有一个 swf 文件,它是一个家庭的平面图,我希望用户能够用两个手指触摸放大和缩小,下面的代码是我尝试过的,但不起作用。 When I test on a touchscreen, it does not zoom when I place two fingers inside the SWF and try to zoom in.当我在触摸屏上测试时,当我将两根手指放入 SWF 并尝试放大时,它不会缩放。

<s:SWFLoader id="floorplanImage" source="@Embed('assets/test2.swf')" width="100%" height="100%" smoothBitmapContent="true" horizontalAlign="center" />

here is my actionscript 3 code这是我的 actionscript 3 代码

import flash.ui.Multitouch;  
            import flash.ui.MultitouchInputMode;  

            Multitouch.inputMode = MultitouchInputMode.GESTURE;

            import flash.events.Event;

            public var selectedItem:Object;

            public function init(): void
            {
                floorplanImage.addEventListener(TransformGestureEvent.GESTURE_ZOOM , onZoom);
            }

            public function onZoom (e:TransformGestureEvent):void{
                floorplanImage.scaleX *= e.scaleX;
                floorplanImage.scaleY *= e.scaleY; 
            }

Please Help!请帮助!

UPDATE更新

I am going the route of gestouch, however with this code, I CANNOT zoom in or out on an SWF.我要走gestouch的路线,但是使用此代码,我无法放大或缩小SWF。 With a regular image it works, but not with SWF unless I am missing something.使用常规图像它可以工作,但不能使用 SWF,除非我遗漏了一些东西。 Here is my code:这是我的代码:

<mx:Script>
                <![CDATA[

                    import org.gestouch.events.GestureEvent;
                    import org.gestouch.gestures.TransformGesture;

                    private var _zoom:TransformGesture;

                    [Embed(source="assets/test2.swf")]
                    private var myClass:Class;
                    private var myMovieClip:MovieClip;


                    private function initModel():void
                    {   

                        myMovieClip = MovieClip(new myClass());
                        swfcontainer.addChild(myMovieClip);

                        _zoom = new TransformGesture(swfcontainer);
                        _zoom.addEventListener(org.gestouch.events.GestureEvent.GESTURE_BEGAN, onGesture);
                        _zoom.addEventListener(org.gestouch.events.GestureEvent.GESTURE_CHANGED, onGesture);

                    }

                    private function onGesture(event:org.gestouch.events.GestureEvent):void
                    {
                        const gesture:TransformGesture = event.target as TransformGesture;
                        var matrix:Matrix = swfcontainer.transform.matrix;

                        // Panning
                        matrix.translate(gesture.offsetX, gesture.offsetY);
                        swfcontainer.transform.matrix = matrix;

                        if (gesture.scale != 1)
                        {
                            // Scale and rotation.
                            var transformPoint:Point = matrix.transformPoint(swfcontainer.globalToLocal(gesture.location));
                            matrix.translate(-transformPoint.x, -transformPoint.y);
                            matrix.scale(gesture.scale, gesture.scale);
                            matrix.translate(transformPoint.x, transformPoint.y);

                            swfcontainer.transform.matrix = matrix;
                        }
                    }

                ]]>
            </mx:Script>

<mx:Image id="swfcontainer" horizontalAlign="center" width="100%" height="100%" />

When I use this with a regular image, it still does not work properly...it doesn't keep the image center when zooming, it does not let me zoom in, only out and when I first use it, it moves the image to the right.当我将它与常规图像一起使用时,它仍然无法正常工作......缩放时它不会保持图像中心,它不允许我放大,只能缩小,当我第一次使用它时,它会移动图像向右。 HOW COME THIS IS SOOOOOO HARD?这怎么这么难?

Please keep in mind I am very very new to Adobe Flex and Actionscript, so please make your answers as clear as possible.请记住,我对 Adob​​e Flex 和 Actionscript 非常陌生,所以请尽可能清楚地回答您的问题。

Your code has no problem,I'll explain what I did for my project.你的代码没有问题,我会解释我为我的项目做了什么。 Maybe it helped, i have Window design app and i load SWF into starling and have issue with zoom and pan;也许它有帮助,我有 Window 设计应用程序,我将 SWF 加载到 Starling 中,但在缩放和平移方面有问题;

FYI: I Use starling and load SWF file with native overlay in starling and zoom pan work仅供参考:我在八哥和缩放平移工作中使用八哥并加载带有本机叠加的 SWF 文件

   _mLoader = new Loader();
 var mRequest:URLRequest = new URLRequest("drawer.swf" + "?nf=" + getTimer());
_mLoader.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE, onCompleteHandler);
 _mLoader.load(mRequest);


     private function onCompleteHandler(loadEvent:flash.events.Event):void
    {
          _mLoader.contentLoaderInfo.removeEventListener(flash.events.Event.COMPLETE, 
           Starling.current.nativeOverlay.addChild(LoaderInfo(loadEvent.currentTarget).content);

    }

And because the library touching the flash was weak i use above lib,and this is to Strong因为接触闪存的库很弱,所以我在 lib 上面使用,这是强

first of all test above lib maybe that's work Without Starling首先在 lib 上进行测试,也许没有 Starling 也能工作

better GESTURE lib than flash lib比闪存库更好的手势库

my zoom code with this lib我使用这个库的缩放代码

     var _zoom:
    _zoom = new TransformGesture(this);
    _zoom.addEventListener(GestureEvent.GESTURE_BEGAN, onGesture);
    _zoom.addEventListener(GestureEvent.GESTURE_CHANGED, onGesture);

private function onGesture(event:org.gestouch.events.GestureEvent):void 
    {

        const gesture:TransformGesture = event.target as TransformGesture;

        var matrix:Matrix = container_movieclip.transform.matrix;



        if (container_movieclip.scaleX!=1 || container_movieclip.scaleY!=1) 
        {
            matrix.translate(gesture.offsetX, gesture.offsetY);
            container_movieclip.transform.matrix = matrix;
        }

        if (gesture.scale != 1)
        {
            var transformPoint:Point = matrix.transformPoint(container_movieclip.globalToLocal(gesture.location));
            matrix.translate(-transformPoint.x, -transformPoint.y);
            matrix.scale(gesture.scale, gesture.scale);
            matrix.translate(transformPoint.x, transformPoint.y);
            container_movieclip.transform.matrix = matrix;

        }

    }

I hope I could help我希望我能帮上忙

如果您将 multiinputMethod 更改为 touchpoint,您的问题就解决了

Multitouch.inputMode=MultitouchInputMode.TOUCH_POINT;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM