I wanted help on a simple issue — converting some ActionScript 2 into AS3. The script is for a sliding panel. I think I need to add my Event Listeners, but I’m not sure how to do it.
On the stage there are three buttons: b1, b2 and closeb. The panel that slides is called bigSlide, and inside it contains separate parts called slide1 and slide2.
Thanks in advance!
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;
}
Start with the enter frame event:
target will be set to the target of the event (this). So you can manipulate its properties. You’ll have to declare “currentSpeed” and “distanceMoved” and your other varibles at the top of your script as AS3 isn’t as forgiving with variable declaration.
To add mouse listeners:
Don’t forget you’ll have to:
import the classes you are referencing.
in AS3 will be
That should get you started. Can edit more later. I wouldn’t call the jump from AS2 to AS3 a “simple issue” if you’ve never done it before. It’s quite different, so good luck!