我在 Adobe Animate 中使用 ActionScript 3 来缩放和平移绘图。每当单击控制面板中的中心按钮时,图像不会出现在中心,它会出现在下方..
此外,平移和缩放也不流畅。我正在使用的代码是创建图像的视频剪辑,并且有一个控制面板来控制缩放和平移。请让我知道使其顺利和可行所需的更改。
AS3代码如下:
import flash.events.MouseEvent;
import flash.events.Event;
var moveSpeed: Number = 5;
var sizeScale: Number = 0.04;
var clickMore: Boolean = false;
var clickLess: Boolean = false;
var clickLeft: Boolean = false;
var clickRight: Boolean = false;
var clickUp: Boolean = false;
var clickDown: Boolean = false;
var clickCenter: Boolean = false;
// --- 点击放大更多:
btMore.addEventListener(MouseEvent.MOUSE_DOWN, moreZoom);
function moreZoom(event: MouseEvent): void {
clickMore = true;
}
btMore.addEventListener(MouseEvent.MOUSE_UP, stopMoreZoom);
function stopMoreZoom(event: MouseEvent): void {
clickMore = false;
}
// --- 点击缩小:
btLess.addEventListener(MouseEvent.MOUSE_DOWN, lessZoom);
function lessZoom(event: MouseEvent): void {
clickLess = true;
}
btLess.addEventListener(MouseEvent.MOUSE_UP, stopLessZoom);
function stopLessZoom(event: MouseEvent): void {
clickLess = false;
}
// --- 单击左移:
btLeft.addEventListener(MouseEvent.MOUSE_DOWN, leftMove);
function leftMove(event: MouseEvent): void {
clickLeft = true;
}
btLeft.addEventListener(MouseEvent.MOUSE_UP, stopLeftMove);
function stopLeftMove(event: MouseEvent): void {
clickLeft = false;
}
// --- 单击向右移动:
btRight.addEventListener(MouseEvent.MOUSE_DOWN, rightMove);
function rightMove(event: MouseEvent): void {
clickRight = true;
}
btRight.addEventListener(MouseEvent.MOUSE_UP, stopRightMove);
function stopRightMove(event: MouseEvent): void {
clickRight = false;
}
// --- 单击上移:
btUp.addEventListener(MouseEvent.MOUSE_DOWN, upMove);
function upMove(event: MouseEvent): void {
clickUp = true;
}
btUp.addEventListener(MouseEvent.MOUSE_UP, stopUpMove);
function stopUpMove(event: MouseEvent): void {
clickUp = false;
}
// --- 点击下移:
btDown.addEventListener(MouseEvent.MOUSE_DOWN, downMove);
function downMove(event: MouseEvent): void {
clickDown = true;
}
btDown.addEventListener(MouseEvent.MOUSE_UP, stopDownMove);
function stopDownMove(event: MouseEvent): void {
clickDown = false;
}
// --- 点击移动中心:
btCenter.addEventListener(MouseEvent.MOUSE_DOWN, centerMove);
function centerMove(event: MouseEvent): void {
clickCenter = true;
}
btCenter.addEventListener(MouseEvent.MOUSE_UP, stopCenterMove);
function stopCenterMove(event: MouseEvent): void {
clickCenter = false;
}
// --- 单击缩放轮:
stage.addEventListener(MouseEvent.MOUSE_WHEEL, handleMouseWheel);
function handleMouseWheel(event: MouseEvent): void {
if (myMCimg.scaleX >= 1) {
myMCimg.scaleX += (event.delta * sizeScale);
myMCimg.scaleY += (event.delta * sizeScale);
} else {
myMCimg.scaleX = 1;
myMCimg.scaleY = 1;
}
}
// --- 动作:
addEventListener(Event.ENTER_FRAME, enterFrame);
function enterFrame(event: Event): void {
if (clickMore == true) {
myMCimg.scaleX += sizeScale;
myMCimg.scaleY += sizeScale;
}
if ((clickLess == true) && (myMCimg.scaleX >= 1)) {
myMCimg.scaleX -= sizeScale;
myMCimg.scaleY -= sizeScale;
}
if (clickLeft == true) {
myMCimg.x -= moveSpeed;
}
if (clickRight == true) {
myMCimg.x += moveSpeed;
}
if (clickUp == true) {
myMCimg.y -= moveSpeed;
}
if (clickDown == true) {
myMCimg.y += moveSpeed;
}
if (clickCenter == true) {
// --- 集中:
myMCimg.scaleX = 1;
myMCimg.scaleY = 1;
myMCimg.x = stage.stageWidth / 2;
myMCimg.y = stage.stageHeight / 2;
}
}
// --- 单击键方向键盘:
stage.addEventListener(KeyboardEvent.KEY_DOWN, pressKeys);
function pressKeys(event: KeyboardEvent): void {
if (event.keyCode == Keyboard.LEFT) {
myMCimg.x -= moveSpeed;
}
if (event.keyCode == Keyboard.RIGHT) {
myMCimg.x += moveSpeed;
}
if (event.keyCode == Keyboard.UP) {
myMCimg.y -= moveSpeed;
}
if (event.keyCode == Keyboard.DOWN) {
myMCimg.y += moveSpeed;
}
if (event.keyCode == Keyboard.ENTER) {
// --- 集中:
myMCimg.scaleX = 1;
myMCimg.scaleY = 1;
myMCimg.x = stage.stageWidth / 2;
myMCimg.y = stage.stageHeight / 2;
}
// --- 点击拖动:
myMCimg.addEventListener(MouseEvent.MOUSE_DOWN, dragMove);
function dragMove(event: MouseEvent): void {
myMCimg.startDrag();
}
myMCimg.addEventListener(MouseEvent.MOUSE_UP, stopDragMove);
function stopDragMove(event: MouseEvent): void {
stopDrag();
}
}