I wonder if there is any difference in execution speed between:
Object( e.target ).labelTextID
and
MovieClip( e.target ).labelTextID
e.target in that case is a MovieClip, but it doesn't matter.
I wonder if there is any difference in execution speed between:
Object( e.target ).labelTextID
and
MovieClip( e.target ).labelTextID
e.target in that case is a MovieClip, but it doesn't matter.
There aren't any difference. Take a look on this sample code:
var obj:Object = new MovieClip();
var v1:Object = Object(obj);
var v2:MovieClip = MovieClip(obj);
Both type castings produce the same op codes:
_as3_findpropstrict Object
_as3_getlocal <1>
_as3_callproperty Object(param count:1)
_as3_coerce Object
_as3_setlocal <2>
_as3_findpropstrict flash.display::MovieClip
_as3_getlocal <1>
_as3_callproperty flash.display::MovieClip(param count:1)
_as3_coerce flash.display::MovieClip
_as3_setlocal <3>
The conclusion is also confirmed by benchmark:
var obj:Object = new MovieClip();
var v1:Object, v2:MovieClip, i:int;
var t:uint = getTimer();
for(i = 0; i < 1000000; i++)
v1 = Object(obj);
trace("Object: ", (getTimer() - t));
t = getTimer();
for(i = 0; i < 1000000; i++)
v2 = MovieClip(obj);
trace("MovieClip: ", (getTimer() - t));
output:
Object: 92
MovieClip: 90
In terms of what type of object you cast to, I cannot be sure, but in terms of how you are doing your casting I would take a look at this answer: https://stackoverflow.com/a/14268394/1346390
The TLDR of it is, use "as" for casting, since it's both faster and safer, since it throws a TypeError if it fails.
There must be no difference between this cast. In both cases the compiler is instructed to explicit cast the e.target no matter of type of e.target.