Casting Variables to a Movie Clip
How can I convert a Gecko object to a movie clip?
function finish(boxname, arrayname:Array):void {
for each (var item:String in arrayname) {
trace(boxname+"_"+item);
var gecko:MovieClip = (boxname+"_"+item) as MovieClip ;
trace(typeof(gecko));
gecko.gotoAndPlay("glow");
}
}
This gives the following error:
high_hsymbol_1
object
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at quizz_fla::MainTimeline/finish()
at quizz_fla:开发者_Go百科:MainTimeline/dropIt()
boxname+"_"+item should be a reference to a movieclip, no need for casting which i think is not possible from a string to a movieclip. You do this with associative arrays. I supposed the movieclips are childs of "this":
var gecko:MovieClip = this[boxname+"_"+item];
this.getChildByName(boxname + "_" + item);
精彩评论