I know this is not possibile to do in an “ethical” way…so what I’m looking for is an Hype hack!
I would like to clone a Symbol instance in runtime: I can easily clone the DOM elements but, of course, Hype uses IDs to control every element inside and their animations…
Here you can find an example of what I achieved until now:
Nice hack!
Cloning isn’t supported now - a “hack” to get it to work fully would mean having an official solution since the Hype runtime makes pretty deep assumptions about the elements uniqueness.
This is a really old thread. So old, the bot asked me if I really want to bother. It’s the closest I can find to what I would like to do. Also, I’m somewhat ignorant when it comes to JavaScript. Sorry. I once learned ActionScript to an adequate degree. Arguably. I bet the Hype developers are pretty sick of hearing that.
I’m trying to create a lot of identical objects and control their visibility randomly. Seems easy, but not so much. I did find that after cloning the objects with JS (thanks to @Cescomare), I could control the visibility of the objects in reverse order. It seems odd that I can control their visibility, but not assign them to an array of IDs. In my example, those last two are invisible, even though I addressed [37] and [4]. Still, I seem to be able to address them? (/me braces himself for scorn and ridicule.)
I ended up doing this the hard way, duplicating the “on” bulb 2,043 times (easy) and naming every instance with a unique, sequential ID (annoying and time consuming).
My question is, can I create one symbol of “bulbOn”, and using JS, duplicate it with loops, giving each instance its own unique ID.
I will spare you my failed attempts.
Since creating the original, I’ve been using this file to learn more about controlling animations in Hype with JS. I’ve found timing and the asynchronous nature of JS to be frustrating. I finally got a random flashing, and (just now) a waterfall version of the marquee working. I suspect that it’s much more processor-intensive than it needs to be, since each instance is its own SVG. It certainly makes the graphic portion of the file difficult to work on. Scrolling, selecting, zooming, etc. are slow and crashy. I finally feel like I have spent enough time trying, and have enough basic understanding to ask "how should I have created 2,043 uniquely ID’d instances-isn’t there a much better way?"saylers-left-random-flashing.hype.zip (218.4 KB) saylers-by-rows.hype.zip (221.9 KB)
Exactly! The cloning! I thought that part would be relatively easy, and I didn’t find a lot of useful examples or reference for a noob like me. It seemed like it would be a common enough technique, especially when one doesn’t know how many of a particular object will be used, or, as in this case, when a lot of duplicate objects are needed. OR I might just be bad at searching.
Thank you for not only taking the time to point me toward the clone extension, but also apply it to this situation. It looks like the clone extension was there all along and I missed it in my searches. Hopefully this application will be helpful to others! OH! And thanks for writing the clone extension in the first place!
What follows is a little off topic here (no clones involved) - but it occurred to me an alternate~easy way to do the cascading light effect on Jeremy’s “Saylers” project would be with a symbol. The following uses eight symbol instances of a master. The cascading lights (5 row) are a screen grab. No coding, just timeline. I used Jeremy’s “bulbs off” background - but it could have been a repeating pattern background image matrix of 7x7 “off” bulbs (to match 28 to a row) to really go lightweight.
The other nice thing about that is CPU.
Going in I knew the amount of elements would be a CPU hog but since this thread is ‘Clone’ I avoided thinking of doing things different with the number of objects but @jims approuch is always best if you can go down that road.
89.7% one is the clones
3.3 is the symbols images.
There are many reasons you may want to clone. The main reason I normally do it is when I need a selection to be generated dynamically. For example
Cloning is part of the Native JS API. But Hype is a self maintained would and does not support cloning and see the new elements so it is a Hack where using cloning with Hype is concerned.
The idea is to create a single symbol, and by some sort of javascript voodoo, to replicate this same symbol horizontally, each one with their own unique ID.
This is useful, in case I need to make adjustments or the client want to add or remove certain features from the thumbnail, I would only edit the master / original symbol, and this is going to be reflected on all 150 thumbnails I am supposed to create.