Control a Timeline with Mouse Position

Position the Clip

Let's write some script to get the main movieClip in the horizontal center of the stage. To calculate the horizontal center, you divide the width of the stage by two. Since we already set sW = Stage.width, we can just reuse that variable:

  1. Click Statements > Variables > set variable
  2. Variable is main._x (remember, this isn't really a variable. This is the x position of the clip main)
  3. Value is sW/2 and make certain you Select the Expression box

OK, it's time to call that init function to make sure everything is running properly.

  1. This action must go outside the closing brace for the init function
  2. Click Deprecated > Actions > call function
  3. Type the Function name init

Now that you can get the clip positioned in the horizontal center, it shouldn't be much of a stretch for you to get the clip in the vertical center. You just need to know that flash returns the height of the stage using Stage.height:

  1. Create a variable called sH equal to the Stage.height
  2. Set the y position of main to half the stage height: