Triggering script in main hierarchy from script that's in a symbol

Hi there,

I wonder if it’s possible to target a node that’s in the main hierarchy of my project, from within a subsymbol.

What I want:
I’m closing a photofeature3D-symbol from a button that’s within this photofeature3D. When this is closed, a function in a script from my main hierarchy should run.

Anyone has an idea?

Thanks in advance!

Ferdy

2 Likes

That’s a great question, I don’t think it’s possible. I hope I’m wrong.

Hi,
Like Mark, I don’t think it’s possible…
But, you can start a loop - with Z.every() - to check whatever you want in your sub symbols.
Cheers

Hi,
Like Mark, I don’t think it’s possible…
But, you can start a loop - with Z.every() - to check whatever you want in your sub symbols.
Cheers

This could indeed be a solution for now, but I don’t think this should be the solution. It feels to me like some sort of workaround.

I’ve seen symbols emitting states. I’ll look into that.

I understand that it seems counter intuitive. :grinning:

It’s just the way I see coding in Zapworks. In my opinion, sub symbols should ignore everything from their parent. On the contrary, parent can get information from their children and fire functions. That way, a symbol can be use by different parents without conflict.

That way, a symbol can be use by different parents without conflict.

I think that is indeed the reason why it works like this.

I’ve found a solution by using emit. In the symbol you can emit an event, which can be picked up by an eventlistener in the parent of that symbol.

In the symbol you can use:

// Emitting an event from script that's within 
// the symbol (Photofeature3D in this case)
symbol.emit('closeSymbol'); 

In the parent you should use:

symbol.nodes.Photofeature3_D.on("closeSymbol", function() {    
// Code to run when the symbol is closed
});

I haven’t tested yet if the parent picks up this event when it’s emitted from a symbol that’s within a symbol.

Hi guys,

Just to clear a few things up -

You can emit an event from within a subsymbol, which can be picked up from the parent but not the other way round (emit from parent to subsymbol)!

You can also export functions, access different nodes and controllers across multiple symbols, more information about this can be found here - Subsymbol communication.

Hope this helps!
George

2 Likes

Hi George,

Thanks!
But how to call an exported function that’s in the main hierarchy from within a subsymbol?

It looks like I can travel down the tree (from main hierarchy to a subsymbol), but I can’t travel up (from a subsymbol to the main hierarchy) the tree. If traveling up is possible, can you please explain how?

As far as I know the Subsymbol communication link doens’t explain this. Or I don’t understand/ need an example :sweat_smile:

But how to call an exported function that’s in the main hierarchy from within a subsymbol?

It looks like I can travel down the tree (from main hierarchy to a subsymbol), but I can’t travel up (from a subsymbol to the main hierarchy) the tree. If traveling up is possible, can you please explain how?

You can’t. The parent can access the child, but the child can not access the parent directly. What you could do is set up an external reference in the subsymbol and write to it in the parent. This way the child can communicate with the parent indirectly.

2 Likes