Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Call a Clip in a function.

New Here ,
Mar 22, 2017 Mar 22, 2017

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.

TOPICS
ActionScript
247
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 22, 2017 Mar 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);

Translate
Community Expert ,
Mar 22, 2017 Mar 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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 22, 2017 Mar 22, 2017

Perfect, thanks a lot !

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 22, 2017 Mar 22, 2017
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines