FLASH AS3 求助:图片点击放大/缩小功能。 要求:以点击图片的位置,为中心点,进行放大缩小。
FLASHAS3求助:图片点击放大/缩小功能。要求:以点击图片的位置,为中心点,进行放大缩小。并不是简单的ScaleX/Y+=1。。。。...
FLASH AS3 求助:图片点击放大/缩小功能。 要求:以点击图片的位置,为中心点,进行放大缩小。
并不是简单的 ScaleX/Y +=1 。。。。 展开
并不是简单的 ScaleX/Y +=1 。。。。 展开
3个回答
展开全部
import flash.display.MovieClip;
import flash.geom.Point;
import flash.events.MouseEvent;
image.addEventListener(MouseEvent.CLICK,clickHandler);
function clickHandler(event:MouseEvent):void{
var mc:MovieClip=event.currentTarget as MovieClip;
var point:Point = new Point(mc.mouseX,mc.mouseY);
scaleAtPoint(mc,point,mc.scaleX+1);
}
function scaleAtPoint(target:MovieClip,point:Point,scale:Number):void{
var stagePoint:Point = target.localToGlobal(point);
target.scaleX=target.scaleY=scale;
var currentStagePoint:Point = target.localToGlobal(point);
target.x-=currentStagePoint.x-stagePoint.x;
target.y-=currentStagePoint.y-stagePoint.y;
}
如果有需要也可以配合TweenLite来添加缩放动画
import flash.geom.Point;
import flash.events.MouseEvent;
image.addEventListener(MouseEvent.CLICK,clickHandler);
function clickHandler(event:MouseEvent):void{
var mc:MovieClip=event.currentTarget as MovieClip;
var point:Point = new Point(mc.mouseX,mc.mouseY);
scaleAtPoint(mc,point,mc.scaleX+1);
}
function scaleAtPoint(target:MovieClip,point:Point,scale:Number):void{
var stagePoint:Point = target.localToGlobal(point);
target.scaleX=target.scaleY=scale;
var currentStagePoint:Point = target.localToGlobal(point);
target.x-=currentStagePoint.x-stagePoint.x;
target.y-=currentStagePoint.y-stagePoint.y;
}
如果有需要也可以配合TweenLite来添加缩放动画
展开全部
1.点击时获取位置,计算偏移量
2.重新设置注册点
3.执行缩放
2.重新设置注册点
3.执行缩放
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼上那个没法用在TweenMax上,以下是我修改的:
import flash.display.MovieClip;
import flash.geom.Point;
import flash.events.MouseEvent;
import com.greensock.TweenMax;
import com.greensock.easing.*;
image.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event: MouseEvent): void {
var mc: MovieClip = event.currentTarget as MovieClip;
var point: Point = new Point(mc.mouseX, mc.mouseY);
scaleAtPoint(mc, point, mc.scaleX + 1);
}
function scaleAtPoint(target: MovieClip, point: Point, scale: Number): void {
var oldScale: Number = target.scaleX;
TweenMax.to(target, .7, {
scaleX: scale, scaleY: scale,
x: target.x - (point.x * scale - point.x * oldScale),
y: target.y - (point.y * scale - point.y * oldScale),
ease: Cubic.easeOut
});
}
感觉最好还是传入元件的外部坐标系,因为有时候传入的是画布的中心点,元件会拖拽缩放等操作,所以修改如下:
import flash.display.MovieClip;
import flash.geom.Point;
import flash.events.MouseEvent;
import com.greensock.TweenMax;
import com.greensock.easing.*;
image.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(e: MouseEvent): void {
var mc:MovieClip=e.currentTarget as MovieClip;
var newScale:Number=mc.scaleX + 1;
//传入的是画布的坐标系 root.x, root.y
scaleAtPoint(mc, new Point(mc.parent.mouseX, mc.parent.mouseY), newScale);
}
function scaleAtPoint(target: MovieClip, newPose: Point, scale: Number): void {
//获取当前目标状态
var oldScale: Number = target.scaleX;
//先算出原始大小元件时的newPose
var initPose:Point=new Point((newPose.x-target.x)/oldScale, (newPose.y-target.y)/oldScale);
TweenMax.to(target, .7, {
scaleX: scale, scaleY: scale,
x: target.x - (initPose.x*scale-initPose.x*oldScale),
y: target.y - (initPose.y*scale-initPose.y*oldScale),
ease: Cubic.easeOut
});
}
import flash.display.MovieClip;
import flash.geom.Point;
import flash.events.MouseEvent;
import com.greensock.TweenMax;
import com.greensock.easing.*;
image.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event: MouseEvent): void {
var mc: MovieClip = event.currentTarget as MovieClip;
var point: Point = new Point(mc.mouseX, mc.mouseY);
scaleAtPoint(mc, point, mc.scaleX + 1);
}
function scaleAtPoint(target: MovieClip, point: Point, scale: Number): void {
var oldScale: Number = target.scaleX;
TweenMax.to(target, .7, {
scaleX: scale, scaleY: scale,
x: target.x - (point.x * scale - point.x * oldScale),
y: target.y - (point.y * scale - point.y * oldScale),
ease: Cubic.easeOut
});
}
感觉最好还是传入元件的外部坐标系,因为有时候传入的是画布的中心点,元件会拖拽缩放等操作,所以修改如下:
import flash.display.MovieClip;
import flash.geom.Point;
import flash.events.MouseEvent;
import com.greensock.TweenMax;
import com.greensock.easing.*;
image.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(e: MouseEvent): void {
var mc:MovieClip=e.currentTarget as MovieClip;
var newScale:Number=mc.scaleX + 1;
//传入的是画布的坐标系 root.x, root.y
scaleAtPoint(mc, new Point(mc.parent.mouseX, mc.parent.mouseY), newScale);
}
function scaleAtPoint(target: MovieClip, newPose: Point, scale: Number): void {
//获取当前目标状态
var oldScale: Number = target.scaleX;
//先算出原始大小元件时的newPose
var initPose:Point=new Point((newPose.x-target.x)/oldScale, (newPose.y-target.y)/oldScale);
TweenMax.to(target, .7, {
scaleX: scale, scaleY: scale,
x: target.x - (initPose.x*scale-initPose.x*oldScale),
y: target.y - (initPose.y*scale-initPose.y*oldScale),
ease: Cubic.easeOut
});
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询