PDA

View Full Version : Static MovieClip() function?



IQAndreas
March 25th, 2009, 10:35 AM
I was looking at a video tutorial, and in order to reference a MovieClip, the instructor used:
var mc:MovieClip = MovieClip(e.currentTarget);

What is the difference between using that, and just using:
var mc:MovieClip = e.currentTarget;


Also, is there any way to easily duplicate a MovieClip? (or any class for that matter) There was a function somewhere back there, but that created a dynamic class. I want an exact replica of the class and all it's properties without manually changing over each and every value.

luiner
March 25th, 2009, 10:50 AM
first option uses "casting" which inform flash player what type ot "target" that is, (it is about 10x faster in some cases) also avoid some problems. If e.curentTarget is not movieClip but just object you cant assign it to mc which is movieClip because not all of objects can be assigned. after casting if it is not proper type you will assign "null".
For duplicate, it is best if you will prepare your own duplicate() function which returns you new object. Because assigning objects retusrn you pointer to same object you use somewhere else

bonnieraymond
March 25th, 2009, 03:09 PM
while we're talking about this, how different between "casting" method and "as" keyword?:
MovieClip(mc);
mc as MovieClip;
which one is better/faster?