【发布时间】: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%" />
当我将它与普通图像一起使用时,它仍然无法正常工作......它在缩放时不会保持图像中心,它不会让我放大,只能缩小,当我第一次使用它时,它将图像向右移动。怎么这么难?
请记住,我对 Adobe Flex 和 Actionscript 非常陌生,所以请尽可能清楚地回答您的问题。
【问题讨论】:
标签: actionscript-3 flash apache-flex