Her

Home Flash & Swish Flash Tutorials Creating a Sliding MC

Creating a Sliding MC

Author: Bluegelmedia.com Author's URL: www.Bluegelmedia.com More by this author

This should be your final outcome. Click on the buttons and see the images slide. You can slide anything.....images, text, or even other movie clips. Notice in this example the images are actually buttons with links:

This code lies directly on the MC you wish to slide (in this case it's a row of button images inside a MC). Be certain to name your movie clip (in this example we named it "webthumbs")

_x defines the starting position of the MC at load time. Then we subtract or add ,depending on direction , the number of pixels we want the MC to move.

onClipEvent (load) {
Scene1_x = _x;
Scene1_y = 0;
Scene2_x = _x-(-92);
Scene2_y = 0;
Scene3_x = _x-(-184);
Scene3_y = 0;
Scene4_x = _x-(-276);
Scene4_y = 0;

//a variable "Scene" is being defined …. Scene1 x coordinates equals _x

}
onClipEvent (enterFrame) {
target_x = this["Scene"+scene+"_x"];

// here target is defined to equal the value of the variable "scene"
// this is done in an equation with strings so that we get "scene"+the value for scene + the property x position
// this is done so that we don't have a value and then _x which is "illegal" in programing. 1_x or 2_x would not be acceptable ....the above string gives us Scene1_x or scene2_x

_x += (target_x-_x)/3;
}

// the last line slows the movement down by thirds.....


The code below lies on the buttons which activate the sliding effect.
Use different numbers to move the MC to the different locations designated above.

This would be the code for button 1 (in our example "effusion solutions"), You would then change the "1" to a "2" for the second button, etc.
note: our MC is named "webthumbs"

on (press) {
webthumbs.scene = "1";
}