tags:

views:

85

answers:

1

Hello. 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;
}
A: 

Start with the enter frame event:

this.addEventListener(Event.ENTER_FRAME, enterFrameHandler);

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

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:

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

Don't forget you'll have to:

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

import the classes you are referencing.

delete this.onEnterFrame;

in AS3 will be

this.removeEventListener(Event.ENTER_FRAME, enterFrameHandler);

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!

Typeoneerror
Just replace the events b1.onRelease = function() {with the above example.
Todd Moses