之前我写过试图将一些AS2转换为AS3。这是一个滑动面板。一个名为bigSlide onstage的大面板包含给儿童MC:slide1和slide2。舞台上还有按钮b1,b2和closeb。
这是AS2:
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);
};
这是我尝试将其转变为AS3。我真的不知道我做得很好。不用说,剧本行为不规律。如果有人对图书馆有任何建议可以让我在没有这么大惊小怪的情况下做同样的事情,那就知道了。
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
stop();
var currentPosition:Number = bigSlide.slide1.x;
var startFlag:Boolean = false;
var finalDestination:Number;
var distanceMoved:Number;
var distanceToMove:Number;
var finalSpeed:Number;
var currentSpeed:Number;
var dir:Number;
function menuSlide (target:MovieClip):void {
if (startFlag == false) {
startFlag = true;
finalDestination = target.x;
distanceMoved = 0;
distanceToMove = Math.abs(finalDestination-currentPosition);
finalSpeed = .3;
currentSpeed = 0;
dir = 1;
if (currentPosition<=finalDestination) {
dir = -1;
} else if (currentPosition>finalDestination) {
dir = 1;
}
this.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
function enterFrameHandler(event:Event):void {
var target:MovieClip = MovieClip(event.target);
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 = target.x;
startFlag = false;
this.removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
}
}
}
b1.addEventListener(MouseEvent.CLICK, onClick1);
function onClick1(event:MouseEvent) {
menuSlide(bigSlide.slide1);
};
bigSlide.addEventListener(MouseEvent.CLICK, onClickBig);
function onClickBig(event:MouseEvent) {
menuSlide(bigSlide.slide2);
};
b2.addEventListener(MouseEvent.CLICK, onClick2);
function onClick2(event:MouseEvent) {
menuSlide(bigSlide.slide2);
};
closeb.addEventListener(MouseEvent.CLICK, onClickClose);
function onClickClose(event:MouseEvent) {
// root.myLoader.contentPath = null;
};
非常感谢!
答案 0 :(得分:0)
当你说“行为不正常”时,它会做什么?
以下是我如何将AS2重写为AS3
stop();
var currentPosition:Number = bigSlide.slide1._x;
var startFlag:Boolean = false;
var finalDestination:Number
var distanceMoved:Number = 0;
var distanceToMove:Number;
var finalSpeed:Number = .3;
var currentSpeed:Number = 0;
var dir:Number;
function menuSlide($target:MovieClip):void {
if (startFlag == false) {
startFlag = true;
finalDestination = $target.x;
distanceMoved = 0;
distanceToMove = Math.abs(finalDestination - currentPosition);
currentSpeed = 0;
if (currentPosition <= finalDestination) {
dir = -1;
} else if (currentPosition > finalDestination) {
dir = 1;
}
addEventListener(Event.ENTER_FRAME, enterFrameHandler, false, 0, true);
}
}
function enterFrameHandler($evt:Event):void {
currentSpeed = Math.round((distanceToMove - distanceMoved + 1) * finalSpeed);
distanceMoved += currentSpeed;
bigSlide.x += dir * currentSpeed;
if (Math.abs(distanceMoved - distanceToMove) <= 1) {
currentPosition = finalPosition;
startFlag = false;
removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
}
b1.addEventListener(MouseEvent.CLICK, onClick1, false, 0, treu);
bigSlide.slide1.more.addEventListener(MouseEvent.CLICK, onClickBig, false, 0, treu);
b2.addEventListener(MouseEvent.CLICK, onClickBig, false, 0, treu);
function onClick1($evt:MouseEvent):void {
menuSlide(bigSlide.slide1);
}
function onClickBig($evt:MouseEvent):void {
menuSlide(bigSlide.slide2);
}