Skip to main content
Participating Frequently
March 22, 2017
Answered

Call a Clip in a function.

  • March 22, 2017
  • 1 reply
  • 282 views

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.

This topic has been closed for replies.
Correct answer kglad

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

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
March 22, 2017

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

AircerAuthor
Participating Frequently
March 22, 2017

Perfect, thanks a lot !

kglad
Community Expert
Community Expert
March 23, 2017

you're welcome.