Copy link to clipboard
Copied
I have an Animate CC Canvas project. My main timeline is one frame with child movieclips on separate layers. I have a function on the main timeline that I need to call inside a child movieclip. I have tried exportRoot.functionName and this.parent.functionName but neither works. Get js error in browser that object does not support method. I can't figure out how to target main timeline from within child movie clip.
Thanks,
Teresa
this.parent.yourfunction();
and use:
this.yourfunction=function(){
}
Copy link to clipboard
Copied
this.parent.yourfunction();
and use:
this.yourfunction=function(){
}
Copy link to clipboard
Copied
Thank you that works. However can you explain why function declaration is
this.yourfunction=function(){
}
and not
function yourfunction() {
}
The reason I ask is if I do it your way it works great when called from child movie clip, however if I call the function from another function on the main timeline, gives javascript error. Something about scope I am not understanding.
Thank you,
Teresa
Copy link to clipboard
Copied
a named function is only referable from the same timeline and the same frame in which it's defined. ie, you can't even call it from the same timeline/different frame.
so, while adobe attempted to make javascript in animate similar to actionscript in animate, there are differences.
you're asking why they don't work the same. i'm saying, while it would be nice if they did work the same, there's no reason to assume they do.
Copy link to clipboard
Copied
Ok, at least I know now why some of my coding is not working as I expected. Thank you.
Copy link to clipboard
Copied
you're welcome.
Copy link to clipboard
Copied
I know this is an old thread but just wanted to say thank you. I couldn't get my head around why my script wasn't working as I expected it to (couldn't call functions from within a movieclip). This explained it very well. and saved me a lot of head scratching!
Copy link to clipboard
Copied
you're (belatedly) welcome.
Copy link to clipboard
Copied
This answer is probably close to my need but not sure how to use it.
I need to use a"ClickToGoToAndStopAtFrame...." but the button is in a movie clip. So I think I understand that a button in a child is trying to move to a frame of the parents timeline and stop. What could I add to the snippet below to get it to jump up to the parent(Scene1) timeline?
My instant name is UIButton_3 and I am trying to go to frame 30 of the parent.
this.UIButton_3.addEventListener("click", fl_ClickToGoToAndStopAtFrame_12.bind(this));
function fl_ClickToGoToAndStopAtFrame_12()
{
this.gotoAndStop(30);
}