Feb 14
AS3 - MovieClipUtil.getFrame() - get frame number by passing frame label
Download Class
Very easy to use:
MovieClipUtil.getFrame(clip, “FRAME_LABEL_1″)
This is a handy tool we had in AS2 but is much more efficient to implement in AS3. In AS2 we had to duplicate the MovieClip, go to that specific frame label, return the current frame, then remove that MovieClip. It was a true ghetto work-around, but it worked. The AS3 is much more clean.
/*
Returns a frame number. Returns MovieClip current frame if nonexistent.
*/
function getFrame($clip:MovieClip, $label:String):Number
{
var arr:Array = $clip.currentLabels
for(var i:Number = 0; i < arr.length; i++ ){
if($label == arr[i].name){
return (arr[i].frame);
}
}
return ($clip.currentFrame);
}
2 Comments so far
Leave a comment
Very handy. Thanks!
…What’s with all the dollar-signs? Is this some kind of PHP-ActionScript fusion thing? Or is there actually a $ operator in AS3 that I’ve missed out?
No, the $ signs are to distinguish the variables that you are passing into the function from the class variables and local variables. Here at work we’ve standardized our coding practices, so everyone here should code the same and we know exactly what we are looking at when we are going thru each others code. But to answer your question completely the $ sign is not necessary and it is not a secret AS3 thing. Thanks for the question.