Here’s a quick tip that will make your Flash projects a bit easier – e.target. When you have more then one object on the stage that does the same thing, ie. is draggable or activates the same event when clicked, e.target will allow you to use a lot less code.
In this example, I’m creating two boxes on the stage, one red and one blue. I want to be able to drag both around the stage. Normally I would make a function for the red box and one for the blue box.
And, of course, the functions for stopDrag().
But now I do it this way. Here’s the entire code to make the boxes and make them draggable:
var redBlock:MovieClip = new MovieClip();
var blueBlock:MovieClip = new MovieClip();
When you MOUSE_DOWN on either the redBlock or the blueBlock, Actionscript will use e.target to make that one targeted by the function.
This will make targeting objects on the stage require a lot less coding.