Copy link to clipboard
Copied
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?
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
...Copy link to clipboard
Copied
Sorry, I don't understand what calling a function in the root timeline has to do with getting stage children movieclips by name.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now