use*_*331 4 apache-flex flash actionscript-3
我似乎在SWFLoader上遇到了Zoom Gestures的问题.我有一个swf文件,这是一个家庭的平面图,我希望用户能够用两个手指触摸放大和缩小,下面的代码是我尝试过但不起作用.当我在触摸屏上进行测试时,当我将两根手指放在SWF中并尝试放大时,它不会缩放.
<s:SWFLoader id="floorplanImage" source="@Embed('assets/test2.swf')" width="100%" height="100%" smoothBitmapContent="true" horizontalAlign="center" />
Run Code Online (Sandbox Code Playgroud)
这是我的动作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;
}
Run Code Online (Sandbox Code Playgroud)
请帮忙!
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%" />
Run Code Online (Sandbox Code Playgroud)
当我使用常规图像时,它仍然无法正常工作...它不会让图像在缩放时保持中心,它不会让我放大,只有当我第一次使用它时,它会移动图像在右边.怎么这么难过?
请记住,我对Adobe Flex和Actionscript非常新,所以请尽可能清楚地回答.
你的代码没有问题,我会解释我为我的项目做了什么.也许它有所帮助,我有Window设计应用程序,我加载SWF到starling,并有缩放和泛问题;
仅供参考:我使用starling并在starling和zoom pan工作中加载带有原生叠加的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);
}
Run Code Online (Sandbox Code Playgroud)
并且因为触摸闪光灯的库很弱,我使用上面的lib,这是强
首先测试上面的lib可能是没有Starling的工作
我的缩放代码与这个库
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;
}
}
Run Code Online (Sandbox Code Playgroud)
我希望我能帮忙
| 归档时间: |
|
| 查看次数: |
182 次 |
| 最近记录: |