Call function on main timeline from nested clip button

I have searched the forum but have no success making a button inside a Clip call a function on the root timeline. I have tried so many things…
Also tried to have the button call a function of clip timeline vs calling it directly from the nested button of Clip.

How does parenting work - Help - The Wick Editor Forums

More wick docs - Demos and Tutorials - The Wick Editor Forums

project._children[0]
and many more. But only allowed two links.

I usually find another way to make things work. But i like to have all functions on one frame on the main timeline and then access them through out the project.
Is this possible or bad practice?

You may want to try something like that
project_functions.wick (3.1 KB)

blurredPixels - Thank you so much for taking time to reply!!!
Looks good. I just have to figure out where to put “parent” for a button in the clip (instead of just calling it from a Clip frame.
And it gives me errors about a text box (tb) when I apply it to my code sample attached in original post.

myFunction on frame 1 of root.

project.cost = function (a,b) {
var c = a+b;
tb.setText c)
}
removed the ( in front of c because it shows up as copyright symbol in this editor.
UPDATE: adding root.tb.text… fixed that issue
ReferenceError: tb is not defined
Error: tb is not defined on line 3 in script “default”.
Error: tb is not defined on line 3 in script “default”.

I don’t get why the keyword “project” is not used when calling from the clip??

SOLVED
Should someone else need help.
Here is a working file of many scenarios calling a function that is on the main timeline.

Thank you blurredPixels for getting me in the right direction.

funcNestingUPDATED12-19-2023_13-15-02.wick (4.1 KB)

You can also use absolute path to your functions.
more_functions.wick (3.2 KB)

That was the first thing i tried, however, the textbox on the main timeline caused an error, which made me think it did not work.
I don’t know why i have to put root.tb.setText(c ) to make it work on my sample. Your example uses console.log. Some glitch, but i worked it out.

Thanks again for sharing…

if you call the function from inside the clip it cannot find tb text inside the clip and throw an error.
Telling the function the absolute path to the text field root.tb makes it always work.

1 Like