SWFLoader 上的 Actionscript 3 和 Flex 4 缩放手势
Actionscript 3 and Flex 4 Zoom Gesture on 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;
}
请帮忙!
更新
我正在走 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 非常陌生,所以请尽可能清楚地回答您的问题。
你的代码没有问题,我会解释我为我的项目做了什么。也许它有帮助,我有 Window 设计应用程序,我将 SWF 加载到八哥中并遇到问题
缩放和平移;
仅供参考:我在 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;
}
}
希望能帮到你
只需将多输入法更改为接触点,即可解决您的问题
Multitouch.inputMode=MultitouchInputMode.TOUCH_POINT;
我似乎对 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 非常陌生,所以请尽可能清楚地回答您的问题。
你的代码没有问题,我会解释我为我的项目做了什么。也许它有帮助,我有 Window 设计应用程序,我将 SWF 加载到八哥中并遇到问题 缩放和平移;
仅供参考:我在 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;
}
}
希望能帮到你
只需将多输入法更改为接触点,即可解决您的问题
Multitouch.inputMode=MultitouchInputMode.TOUCH_POINT;