将简单AS2转换为AS3

时间:2010-02-11 18:14:48

标签: actionscript

我想要一个简单问题的帮助 - 将一些ActionScript 2转换为AS3。该脚本适用于滑动面板。我想我需要添加我的事件监听器,但我不知道该怎么做。

在舞台上有三个按钮:b1,b2和closeb。滑动的面板称为bigSlide,其内部包含名为slide1和slide2的单独部分。

提前致谢!

stop();

var currentPosition:Number = bigSlide.slide1.x;
var startFlag:Boolean = false;
menuSlide = function (input:MovieClip) {
if (startFlag == false) {

startFlag = true;

var finalDestination:Number = input.x;
var distanceMoved:Number = 0;
var distanceToMove:Number = Math.abs(finalDestination-currentPosition);
var finalSpeed:Number = .3;
var currentSpeed:Number = 0;
var dir:Number = 1;

if (currentPosition<=finalDestination) {
dir = -1;
} else if (currentPosition>finalDestination) {
dir = 1;
}

this.onEnterFrame = function() {
currentSpeed = Math.round((distanceToMove-distanceMoved+1)*finalSpeed);
distanceMoved += currentSpeed;
bigSlide.x += dir*currentSpeed;
if (Math.abs(distanceMoved-distanceToMove)<=1) {
bigSlide.x = maskMovie.x-currentPosition+dir*distanceToMove;
currentPosition = input.x;
startFlag = false;
delete this.onEnterFrame;
}
};
}
};
b1.onRelease = function() {
menuSlide(bigSlide.slide1);
};
bigSlide.slide1.more.onRelease = function() {
menuSlide(bigSlide.slide2);
};
b2.onRelease = function() {
menuSlide(bigSlide.slide2);
};

closeb.onRelease = function() {
 root.myLoader.contentPath = null;
}

1 个答案:

答案 0 :(得分:1)

从输入框架事件开始:

this.addEventListener(Event.ENTER_FRAME, enterFrameHandler);

function enterFrameHandler(event:Event):void
{
    var target:MovieClip = MovieClip(event.target);
}

目标将设置为事件的目标(this)。所以你可以操纵它的属性。你必须在脚本的顶部声明“currentSpeed”和“distanceMoved”以及你的其他变量,因为AS3不像变量声明那样宽容。

添加鼠标侦听器:

b1.addEventListener(MouseEvent.CLICK, onClick);
function onClick(event:MouseEvent)
{
    menuSlide();
}

不要忘记你必须:

import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;

导入您正在引用的类。

delete this.onEnterFrame;
AS3中的

将是

this.removeEventListener(Event.ENTER_FRAME, enterFrameHandler);

这应该让你开始。可以稍后编辑。如果你以前从未做过,我不会把从AS2到AS3的跳转称为“简单问题”。这是完全不同的,祝你好运!