ActionScript 3 放大鼠标位置
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 放大鼠标位置相关的知识,希望对你有一定的参考价值。
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
import fl.motion.MatrixTransformer;
const TWEEN_IN:String = "tweenIn";
const TWEEN_OUT:String = "tweenOut";
var tweenDirection:String;
var internalPoint:Point;
var externalPoint:Point;
var tw:Tween;
var square:Sprite = new Sprite();
square.graphics.beginFill(0xFF0000);
square.graphics.drawRect(0, 0, 100, 100);
square.x = stage.stageWidth/2 - square.width/2;
square.y = stage.stageHeight/2 - square.height/2;
addChild(square);
square.addEventListener(MouseEvent.CLICK, zoomIn);
function zoomIn($e:MouseEvent):void
{
square.removeEventListener(MouseEvent.CLICK, zoomIn);
internalPoint = new Point(square.mouseX, square.mouseY);
externalPoint = new Point(stage.mouseX, stage.mouseY);
var marker:Sprite = new Sprite();
marker.graphics.beginFill(0);
marker.graphics.drawCircle(0, 0, 5);
marker.x = internalPoint.x;
marker.y = internalPoint.y;
marker.name = "marker";
square.addChild(marker);
tweenDirection = TWEEN_IN;
tw = new Tween(null, "", Elastic.easeOut, square.scaleX, 4, 1, true);
tw.addEventListener(TweenEvent.MOTION_CHANGE, _syncScale);
tw.addEventListener(TweenEvent.MOTION_FINISH, _cleanTween);
}
function _syncScale($e:TweenEvent):void
{
square.scaleX = square.scaleY = tw.position;
var matrix:Matrix = square.transform.matrix;
MatrixTransformer.matchInternalPointWithExternal(matrix, internalPoint, externalPoint);
square.transform.matrix = matrix;
}
function _cleanTween($e:TweenEvent):void
{
tw.removeEventListener(TweenEvent.MOTION_CHANGE, _syncScale);
tw.removeEventListener(TweenEvent.MOTION_FINISH, _cleanTween);
tw = null;
if(tweenDirection == TWEEN_IN)
stage.addEventListener(MouseEvent.CLICK, zoomOut);
else if(tweenDirection == TWEEN_OUT)
square.addEventListener(MouseEvent.CLICK, zoomIn);
}
function zoomOut($e:MouseEvent):void
{
stage.removeEventListener(MouseEvent.CLICK, zoomOut);
externalPoint = square.localToGlobal(internalPoint);
internalPoint = square.globalToLocal(externalPoint);
square.removeChild(square.getChildByName("marker"));
tweenDirection = TWEEN_OUT;
tw = new Tween(null, "", Strong.easeOut, square.scaleX, 1, 1, true);
tw.addEventListener(TweenEvent.MOTION_CHANGE, _syncScale);
tw.addEventListener(TweenEvent.MOTION_FINISH, _cleanTween);
以上是关于ActionScript 3 放大鼠标位置的主要内容,如果未能解决你的问题,请参考以下文章