将变量转换为影片剪辑

时间:2010-04-27 18:48:05

标签: flash actionscript-3

如何将Gecko对象转换为影片剪辑?

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");
    }

  }

这会出现以下错误:

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::MainTimeline/dropIt()

2 个答案:

答案 0 :(得分:3)

boxname +“_”+ item应该是对movieclip的引用,不需要我认为无法从字符串转换为movieclip。 您可以使用关联数组执行此操作。我认为影片剪辑是“这个”的孩子:

var gecko:MovieClip = this[boxname+"_"+item];

答案 1 :(得分:0)

this.getChildByName(boxname + "_" + item);