A project I've inherited includes a piece of code that sends a MovieClip to a frame with a specific label (in my case the label was 'disabledframe'). Unfortunately some of the MovieClips that extend this base class do not contain said frame label which resulted in a runtime error.
To make matters worse I do not have access to the original assets and adding the rame was therefore not an option. I knew that I could work around this problem by checking if the frame label exists, but couldn't remember how it was done...
Thanks to the power of Twitter and its awesome inhabitants I had the answer delivered within seconds - special thanks to @stray_and_ruby, @stevecarpenter (although his response time to my tweet was at least 24 seconds slower than the first correct answer, he needs to work on that ;-) and an anonymous commenter by the name of DaveW who pointed out a major error in the initial code I posted - oops.
2trace(movieClipHasLabel(mc, "blah")); // traces true
3
4function movieClipHasLabel(movieClip:MovieClip, labelName:String):Boolean {
5 var i:int;
6 var k:int = movieClip.currentLabels.length;
7 for (i; i < k; ++i) {
8 var label:FrameLabel = movieClip.currentLabels[i];
9 if (label.name == labelName)
10 return true;
11 }
12 return false;
13}
By the way - since we are talking about Twitter - if you enjoy my blog posts then why not follow me?

#1 by DaveW on 11/24/11 - 2:33 AM
// assuming you have a movie clip named 'mc' with a label named 'blah'
trace(mc.currentLabels.indexOf("blah") != -1); // traces false
trace(movieClipHasLabel(mc, "blah")); // traces true
function movieClipHasLabel(movieClip:MovieClip, labelName:String):Boolean {
var i:int;
var k:int = movieClip.currentLabels.length;
for (i; i < k; ++i) {
var label:FrameLabel = movieClip.currentLabels[i];
if (label.name == labelName)
return true;
}
return false;
}
#2 by Stefan Richter on 11/24/11 - 11:46 AM