Movement in FlashMX / Actionscript

I know nothing about actionscript… but going through the tutorials here found one on movement in Flash MX using Actionscript. I had a little play around with it ( the one with the little blue box) and thought to myself “how would you make the box stop in the center instead of carrying on to the edge of the page ?”

So there’s my question… also what if you wanted an object to go from the edge, to the centre, stop and fade out… could you do that using actionscript ??

Thanks for your help…

Oh yeah man… You can do nearly anything with actionscript… hehe…

I don’t know if it was easing you read up on… But this should help you out some in figuring out how to move something to the center then have it stop and fade out…

Put this in the main frame f your movie… Actions - Frame…



_root.onLoad = function()
{
   centerPiece = Stage.width();
   fadeOut = FALSE;
}

_root.onEnterFrame = function()
{
   if(yourMovieClip._x <= centerPiece)
   {
      yourMovieClip._x += 2;
   } else {
      fadeOut = TRUE;
   }
   if(fadeOut == TRUE && yourMovieClip._alpha > 0)
   {
      yourMovieClip._alpha -= 5;
   }
}


I’ve gotta gte going… But that should help you out man… Hope someone can explain this if needed… I won’t be back until tomorrow night.

here’s what i do almost every time to fade or move a movie clip …


/* 
Math.ceil if the final value is higher than the initial value
Math.floor if the final value is lower than the initial value
without using those methods the script would fail because every
operation generates decimals so we need to round the number
to the lower or higher integer to match our final values
*/

// end x value
endX = 0
// end alpha value
endA = 0
// speed value
speed = .1

instanceName.onEnterFrame = function () {
	// if mc x is not equal to endX
	if (this._x != endX) {
		// move mc x to endX
		this._x += Math.ceil ((endX - this._x) * speed)
	// if mc x equals endX
	} else {
		// if mc alpha is not equal to endA
		if (this._alpha != endA) {
			// decrease mc alpha to 0
			this._alpha += Math.floor ((endA - this._alpha) * speed)
		}
	}
}

don’t forget to replace instanceName with the actual instance name of your movie clip
endX with your final x coordinate and endA with your final Alpha value