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

Get stage children movieclips by name from external script in html5 canvas

New Here ,
May 03, 2018 May 03, 2018

i'm trying to call a function in the root time line from an external script. this is the function :

function myFunction(){ this.mc.gotoAndStop(1); }

how can i call it from an external script in the html file?

369
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

LEGEND , May 04, 2018 May 04, 2018

Err, okay. It doesn't matter much at all what the function does, the way you call it will be the same regardless.

To make a function visible to external code, you have to assign it as a property of its container object. So you'd do this in the root timeline:

this.myFunction = function(){ this.mc.gotoAndStop(1); }

Then call it from your external code like this:

exportRoot.myFunction();

Of course, if that's literally all this function will ever do, you could just skip the function and do it directly fr

...
Translate
LEGEND ,
May 03, 2018 May 03, 2018

Sorry, I don't understand what calling a function in the root timeline has to do with getting stage children movieclips by name.

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 ,
May 04, 2018 May 04, 2018

because the function "myFunction" get a stage childern named "mc".

if i set the function in the document context i can call the function but the mc named "mc" returns null.

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
LEGEND ,
May 04, 2018 May 04, 2018
LATEST

Err, okay. It doesn't matter much at all what the function does, the way you call it will be the same regardless.

To make a function visible to external code, you have to assign it as a property of its container object. So you'd do this in the root timeline:

this.myFunction = function(){ this.mc.gotoAndStop(1); }

Then call it from your external code like this:

exportRoot.myFunction();

Of course, if that's literally all this function will ever do, you could just skip the function and do it directly from your external code:

exportRoot.mc.gotoAndStop(1);

Although there are advantages to maintaining an abstraction layer between internal and external code.

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