Obviously this is a simplified example, but this would allow me to have one function that adapts to other factors (such as which item is being dragged) without having to write additional handling code.
Thanks for your response! CSS classes would work for the above example, but I do wonder whether that would be possible in all instances. What if the classname was used for other functionality, for instance. I will definitely keep your suggestion in mind though, thanks!
To me it seems that passing parameters to a function is such a core feature of Javascript, I am surprised it is not implemented in Hype’s UI.
Thanks again h_classen, here is a similar example you may be able to help me with:
What if I have a function, playVid() that does something like:
Sets SRC attribute of HTML5 video
Checks if video has cached enough to play
Sets playhead to 0:0:10
Plays video
Then I want to call it on multiple scene loads, or from button clicks, like so:
playVid(big_buck_bunny); //plays bunny movie
playVid(elephants_dream); //plays elephant movie
In the case of button clicks, it seems you are saying I give the button a class of “big_buck_bunny” or “elephants_dream” and fetch the class as part of my function, is that correct?
But what if I want to attach the function to a scene load?
Hello again, just wanted to mention that the solution to use classes proposed by hans does indeed work.
I still do, however, want to put my original feature request forward as I think passing values to a function is such a basic operation it would be good to be able to achieve this without using workarounds.
I agree. It would be good to be able to add values in the JS sections in the UI and Actions/Timelines
AndI think what we should have is also in the Element’s identity inspector an area to add various data attributes to the element. ( as @h_classen suggests )
The best way that I have used to keep my document clean has been assigning ids to elements and using switch cases. For example,
function speak( hypeDocument, element, event){ switch (element.id){ case "hiButton": alert( "hi" ); break; case "byeButton": alert( "bye" ); break; } }
This would work perfectly fine. I also created and external js file, which has functions that are extremely long and complicated, and I just call them in the Hype document when needed. This has kept my documents extremely clean!