ActionScript 3和Flex 4缩放手势在SWFLOADER上



我似乎在swfloader上的缩放手势问题。我有一个SWF文件,该文件是房屋的平面图,希望用户能够用两个手指触摸放大和放大,以下代码是我尝试过的,并且不起作用。当我在触摸屏上测试时,当我将两个手指放在SWF内并尝试放大时,它不会缩放。

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

这是我的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; 
            }

请帮助!

update

我要去gestouch的路线,但是使用此代码,我不能在SWF上放大或缩小。使用常规图像,它可以正常工作,但是除非我缺少某些东西,否则不使用SWF。这是我的代码:

<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%" />

当我与常规图像一起使用时,它仍然无法正常工作...它在缩放时不会保留图像中心,它不允许我放大,只能放大,并且首次使用它时,将图像向右移动。这怎么很难?

请记住,我对Adobe Flex和ActionScript非常陌生,因此请尽可能清楚您的答案。

您的代码没有问题,我将解释我为项目所做的事情。也许它有所帮助,我有窗户设计应用程序,然后将SWF加载到Starling并遇到问题用变焦和锅;

fyi:我在Starling和Zoom Pan Work

中使用Starling和Load 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);
    }

,由于碰到闪光灯的库很弱,所以我在lib上方使用,这是强大的

首先,上面的测试中的lib也许这是工作而没有starling

手势比Flash Lib更好的手势

使用此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;
        }
    }

我希望我能帮助

如果您将多输入method更改为touchpoint

,则简单地解决了您的问题
Multitouch.inputMode=MultitouchInputMode.TOUCH_POINT;

最新更新