【问题标题】:Actionscript 3 and Flex 4 Zoom Gesture on SWFLoaderSWFLoader 上的 Actionscript 3 和 Flex 4 缩放手势
【发布时间】:2017-11-28 01:08:13
【问题描述】:

我似乎对 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; 
            }

请帮忙!

更新

我正在走 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%" />

当我将它与普通图像一起使用时,它仍然无法正常工作......它在缩放时不会保持图像中心,它不会让我放大,只能缩小,当我第一次使用它时,它将图像向右移动。怎么这么难?

请记住,我对 Adob​​e Flex 和 Actionscript 非常陌生,所以请尽可能清楚地回答您的问题。

【问题讨论】:

    标签: actionscript-3 flash apache-flex


    【解决方案1】:

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

    Multitouch.inputMode=MultitouchInputMode.TOUCH_POINT;
    

    【讨论】:

      【解决方案2】:

      你的代码没有问题,我会解释我为我的项目做了什么。也许它有帮助,我有 Window 设计应用程序,我将 SWF 加载到 starling 并有问题 带缩放和平移;

      仅供参考:我在 Starling 和缩放平移工作中使用 Starling 并加载带有本机叠加层的 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 也可以工作

      better GESTURE lib than flash 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;
      
              }
      
          }
      

      希望能帮到你

      【讨论】:

      • 嘿,我今天查看了库,我对 Adob​​e Flex 和 Actionscript 3 还很陌生,我正在努力理解它,这需要一些时间。是否会这样做,只放大图像而不是整个舞台,并在放大和缩小时保持图像中心?另外我可能会使用 png 或 svg 或 jpg 这种方法适用于那些人吗?
      • 是的,它的工作,我用这个库做了类似你的项目(放大和缩小时保持图像中心),肯定适用于 PNG,但我没有尝试 SVG,它必须工作。GitHub 中的示例和问题对我帮助很大Examples
      • 我在我的 Adob​​e Flex 项目中安装它时遇到问题......我正在使用 Adob​​e Flash Builder。
      • 第二行代码出错:The this keyword can not be used in static methods. It can only be used in instance methods, function closures, and global code.
      • 我也收到了诸如访问未定义属性_zoom之类的错误。 - 访问可能未定义的属性 _zoom。访问未定义的 onGesture 属性。
      猜你喜欢
      • 2018-12-02
      • 1970-01-01
      • 2018-01-13
      • 2014-07-04
      • 2017-11-27
      • 1970-01-01
      • 2016-08-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多