Reputation: 43
I have a couple of different buttons which all have corresponding MovieClips. e.g. the button is name "horse_btn" and the MovieClip "horse_btn_mc".
Now I need one function which plays the corresponding MovieCLip when the button is clicked. I tried this:
horse_btn.addEventListener(MouseEvent.MOUSE_OVER, over);
function over(e:MouseEvent)
{
var mc = e.currentTarget.name;
mc += "_mc";
mc.gotoAndPlay(1)
}
But I keep getting this error: TypeError: Error #1006: value is not a function. What am I doing wrong?
Upvotes: 0
Views: 50
Reputation: 497
Type String
dos not have a field gotoAndPlay
. For get the display object you have to use "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);
See doc: DisplayObjectContainer.getChildByName().
Upvotes: 0