Making A Trashcan
We are going to be doing something a little different in this tutorial.
Name layer 1 trashcan, now draw a rectangle on the stage, and convert it to a movie
Clip(this will be a trashcan). Now give the rectangle an instance name of trashcan.
Okay, now insert a new layer and call it rubbish. Obviously this will be the layer that contains the thing we want to put in the trashcan. On the layer rubbish draw out the thing that you want to put in the trashcan, covert the rubbish in to a movie clip. Give the rubbish an instance name of rubbish.
Right click on the first frame of the rubbish layer and select actions.
now type this in on the first line:
// Drag a piece of garbage.
rubbish.onPress = function() {
this.startDrag(false);
};
// When the garbage is dragged over the trashcan, make it invisible.
rubbish.onRelease = function() {
this.stopDrag();
// Convert the slash notation to dot notation using eval.
if (eval(this._droptarget) == trashcan) {
rubbish._visible = false;
}
};
Note: notice how there are //above the codes, they explain what the code does.
Test the movie, click on the rubbish and drag it over the trashcan, when you release the rubbish, it disappears. Well Done.
NOTE ABOUT THIS TUTORIAL: IT WOULD BE A GOOD IDEA TO PUT THE RUBBISH LAYER ABOVE THE TRASHCAN LAYER.
No comments:
Post a Comment