AS3 1 从不同的按钮播放不同的 MovieClips 的功能?

AS3 1 function to play different MovieClips from different buttons?

我有几个不同的按钮,它们都有对应的 MovieClip。 例如按钮是名称 "horse_btn" 和 MovieClip "horse_btn_mc".

现在我需要一个函数,它可以在单击按钮时播放相应的 MovieCLip。我试过这个:

horse_btn.addEventListener(MouseEvent.MOUSE_OVER, over);

function over(e:MouseEvent)
{
    var mc = e.currentTarget.name;
    mc += "_mc";
    mc.gotoAndPlay(1)
}

但我不断收到此错误: 类型错误:错误#1006:值不是函数。 我究竟做错了什么?

类型 String 没有字段 gotoAndPlay。要获取显示对象,您必须使用 "getChildBy...."-methods.

var theName = e.currentTarget.name + "_mc";
//var yourContainer:DisplayObjectContainer = e.currentTarget.parent as DisplayObjectContainer;
var mc:MovieClip = yourContainer.getChildByName( theName ) as MovieClip;
mc.gotoAndPlay(1);

参见doc: DisplayObjectContainer.getChildByName()