Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Actionscript 3 and Flex 4 Zoom Gesture on SWFLoader

I seem to be having issue with Zoom Gestures on a 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. When I test on a touchscreen, it does not zoom when I place two fingers inside the SWF and try to zoom in.

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

here is my actionscript 3 code

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. With a regular image it works, but not with SWF unless I am missing something. 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.

like image 338
user979331 Avatar asked Jun 24 '17 16:06

user979331


2 Answers

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;

FYI: I Use starling and load SWF file with native overlay in starling and zoom pan work

   _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

first of all test above lib maybe that's work Without 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

like image 176
Alireza Avatar answered Sep 28 '22 17:09

Alireza


simply your issue solved if you changed multiinputMethod to touchpoint

Multitouch.inputMode=MultitouchInputMode.TOUCH_POINT;
like image 33
Yoones Mashayekhi Avatar answered Sep 28 '22 18:09

Yoones Mashayekhi