Skip to main content
MB-HR
Participant
May 3, 2018
Answered

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

  • May 3, 2018
  • 1 reply
  • 402 views

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?

This topic has been closed for replies.
Correct answer ClayUUID

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.

1 reply

Legend
May 3, 2018

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

MB-HR
MB-HRAuthor
Participant
May 4, 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.

ClayUUIDCorrect answer
Legend
May 4, 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 from your external code:

exportRoot.mc.gotoAndStop(1);

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