Skip navigation
Currently Being Moderated

Moving a Movieclip using Actionscript...

Feb 11, 2008 10:30 AM

I'm trying to move a movie clip which has my main content in by having it scroll when a button (the button is independent to the clip I'm moving) is moused over, so that if the "up" button is moused over it will slowly move the movieClip in that direction.

At present I have code (attached) that responds to my mouse being over a button by moving my movieClip (contentArea) unless the movie clip's x value is already at 0, in which case it stops.

However, it does this all in one go, so it instantly is setting x to 0.

Does anyone know how I could make this gradual, so say for every second the mouse is over the scroll area the movie clip would move a set number of pixels that way? Or am I over complicating things and there is an easier way to do this? It has to be mouse over as opposed to clicking as I want it to be intuitive.

I'd be really grateful if anyone could help,


  • Currently Being Moderated
    Feb 11, 2008 10:48 AM   in reply to amillionpieces
    yeah, the 'while' event will continue to loop and increment the value until it reaches the goal the will execute. Instead you need to use an 'onEnterFrame' event to acheive this. I would also recommend placeing your codes on an 'actions' layer in the main timeline as a best practice. so create a new layer on the main timeline called 'actions' and place the following code:

    (ps. of course the value '_x' will scroll the contentArea horizontally, you may need to use '_y')
    (pss. also the instance name should be that of your button, I have 'up_btn' here, use your instance name)

    Mark as:
  • Currently Being Moderated
    Feb 11, 2008 11:27 AM   in reply to amillionpieces
    you're welcome :)

    it does make it much easier to find, reference, and 'point' to other content within your code.
    Mark as:
  • Currently Being Moderated
    Feb 11, 2008 12:15 PM   in reply to amillionpieces
    no it won't matter, that's really not too much code. However, you would not have to do that, you could assign the method(s) to your buttons using an array and a loop. even using a 'speed' property to use the same method for both fast and slow scrolling, and a 'direction' property, to tell the method which way to scroll.

    as far as the positioning goes, that shouldn't matter to the operation of the buttons, but it may effect your conditional statement (to stop the scrolling when necessary in the max direction) so you may want to use a variable and assign it on resizing.
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points