Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 629045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:42:09+00:00 2026-05-13T19:42:09+00:00

Previously I wrote on trying to convert some AS2 to AS3. It’s a sliding

  • 0

Previously I wrote on trying to convert some AS2 to AS3. It’s a sliding panel. A big panel called bigSlide onstage contains to children MC’s: slide1 and slide2. Onstage there are also buttons b1, b2 and closeb.

Here’s the 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);
};

And here is my attempt at turning it into AS3. I really don’t know what I’m doing very well. Needless to say, the script acts erratically. If anyone has any suggestions of libraries that will allow me to do the same thing without all this fuss, lemme know.

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;
};

Thanks so much!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:42:09+00:00Added an answer on May 13, 2026 at 7:42 pm

    When you say “acts erratically”, what does it do?

    Here is how I would rewrite the AS2 into 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);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to delete a previously created file called a\ . I tried
I'm trying to write some tests around some code previously written before I start
I previously wrote some utilities in Perl, and I am now rewriting them in
About project: I'm trying to write CMS-like web-site on Java. Previously I used PHP
Previously in ext 3.0 we had Tree Panel built from XML response. For that
Previously I have asked to strip text from a field and convert it to
I'm trying to append some data to a file, but in some cases want
Previously i wrote an app that used reflection to serialize data from json to
I am trying to configure some basic HTTP authentication over HTTPS using the spring
I'm trying to write some code that deletes an image off the hard-disk once

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.