Copy link to clipboard
Copied
Hello,
I want to use gotoAndPlay for a clip in a function but i want to give the name of the clip to this function. I tried to do it but i still got Error #1034: Type Coercion failed.
This is my code:
function Goo(blin:String):void
{
MovieClip(blin).gotoAndPlay(3);
}
Goo('rom');
The Clip rom is on the stage.
Thanks for the answer.
1 Correct answer
if you're passing a string (eg, the instance name of the movieclip), use getChildByName:
function Goo(blin:String):void
{
MovieClip(getChildByName(blin)).gotoAndPlay(3);
}
Goo('rom');
or, even easier, just pass a reference to the mc itself:
function Goo(blin:MovieClip):void
{
MovieClip(blin).gotoAndPlay(3);
}
Goo(rom);
Copy link to clipboard
Copied
if you're passing a string (eg, the instance name of the movieclip), use getChildByName:
function Goo(blin:String):void
{
MovieClip(getChildByName(blin)).gotoAndPlay(3);
}
Goo('rom');
or, even easier, just pass a reference to the mc itself:
function Goo(blin:MovieClip):void
{
MovieClip(blin).gotoAndPlay(3);
}
Goo(rom);
Copy link to clipboard
Copied
Perfect, thanks a lot !
Copy link to clipboard
Copied
you're welcome.

