Sunday, February 18, 2007

Parallax Function


GEN_positionInParallax = function (thisMovieClip, theBoundsMovieClip, theLeaderMovieClip) {
//
// X...
//get offset % by comparing theLeaderMovieClip with theBoundsMovieClip
extraXSpace = (theLeaderMovieClip._width)-(theBoundsMovieClip._width);
westGap = (theBoundsMovieClip._x)-(theLeaderMovieClip._x);
leaderWestGapXPercentage = westGap/extraXSpace;
//set position
followerExtraXSpace = (thisMovieClip._width)-(theBoundsMovieClip._width);
thisMovieClip._x = (-(followerExtraXSpace*leaderWestGapXPercentage))+theBoundsMovieClip._x;
//
// Y...
//get offset % by comparing theLeaderMovieClip with theBoundsMovieClip
extraYSpace = (theLeaderMovieClip._height)-(theBoundsMovieClip._height);
northGap = (theBoundsMovieClip._y)-(theLeaderMovieClip._y);
leaderWestGapYPercentage = northGap/extraYSpace;
//set position
followerExtraYSpace = (thisMovieClip._height)-(theBoundsMovieClip._height);
thisMovieClip._y = (-(followerExtraYSpace*leaderWestGapYPercentage))+theBoundsMovieClip._y;
};

No comments: