Add or Clone Symbols Dynamically?

It's been a few years since I saw this in the forum and was curious if anyone has found a solution to do either of these?

  1. Add a symbol in the library to the stage dynamically at runtime, OR
  2. Programmatically clone a symbol instance that's on the stage?

The ability to do this would be a ENORMOUS help.

Thank you!

1 Like

Thanks for the request! This isn't presently available but is definitely an important feature :wink:.

(There are a few hacks that can get a little of the functionality if you search "clone symbol" on the forums but none of them fully interact with the hype runtime that would be the main benefit)

1 Like

@jonathan I figured it out - modified the cloneElement hypeExtension and it work BEAUTIFULLY!

I once came up with a solution: it allows you to duplicate a symbol but only activates a single copy of a symbol at any given state. Explanation: When you duplicate symbols—simply by duplicating the HTML—you encounter the problem of also duplicating the IDs, and the runtime only manages one set of IDs. So I implemented a workaround that deactivates all the IDs by transferring them to the data-id attribute. Then, when you click on it, it reactivates by copying all the IDs back over. That's a hack, and I used that hack in this extension. You could extract the activation code from there since the extension mainly includes a grid solution. But if you only want the activation part, it's available within the extension. Hype Template Grid

To be honest, it's a hack. And I mainly used it as a proof of concept because my main goal was the grid, and not the activation.

2 Likes

@MaxZieb 99.9999% of my career in interactive design has been defined by "it's a hack (but at least it works!)" :heart:

I did run into one issue - once I successfully cloned the symbols, I get an error when I attempted to play an instance's internal timeline. I'm assuming this is probably due to the fact that all the duplicates contain the same timeline name.

As long as you switch over the ids it should work. Did you do that?

I tried giving the new clones unique id's but kept getting console errors