Maintaining Colors when clicking

(Ricky) #1

hello there , I have problem with the project that i want to make . I try to make a rectangle that will change the color from orange to red when its hover , and when it get clicked to . But i have problem maintaining the red color when it get clicked , just to show that this button is currently active , until you pressed it again , or press the others button .

Here is the file : (12.4 KB)


Hi Ricky!

Hype Project Demo: Button Toggle - (18.6 KB)


Timelines: In addition to the “Main Timeline” there is also “Button State” which sets the colors of the buttons. “Button01” is active (red color) at one second; “Button02” is active at two seconds, etc.

(2) Functions:
“setBtnColor” - overrides Hype’s “Normal~Hover” default behavior.
“setBtnState” - sets the button color as needed using the “Button State” timeline.

I have annotated the code thoroughly so I won’t replicate the annotation here.


Typically the user interface uses a unique color for the “hover” event. In the demo I have set the “hover” to match the “active” or “selected” state as You stipulated.

The code is set up to register a 2 digit ending on the ID for the button; so buttons with IDs below “10” will need to be labeled using “Button01”, “Button02”,“Button03”.

You could use another name like “menuButton” … just make sure that the last 2 digits of the button name matches the “Button State” timeline location in seconds. So the “active” state (red color) for “menuButton07” would be located at 7 seconds on this timeline.


Edit - Additional Notes

As it is now, it is easy to copy and paste the “Background Color” property setting from one button to a new one in the “Button State” timeline; then adjust the positioning for the “active” time for that new button.

However, if You have more than a handful of buttons or You intend to use this set-up in other projects, it might be more efficient~portable to create a complete JavaScript solution rather than a JavaScript~Timeline hybrid.

The difference would be using the color of the button as the key indicator instead of a button’s timeline location - along with a variable that tracked the active button ID (and so its color) - as well as variables (or an array) that stored an individual button’s default (inactive, non-selected) color. If the default state was the same color for all buttons it would make things easier.

(Ricky) #3

Wow , It’s perfectly match with with what I want , you are rock man .
Thanks for your big help

(Ricky) #4

by the way , is the setBtnColor only effect on button , or it also can affect on shape like rectangle . And does it also affect on group ?


Hi Ricky!

What ever element You use can be set up the same way as a button (which of course is an element); keeping in mind my example was designed to be a toggle, only one element at a time is selected based on the element’s unique ID.

(Ricky) #6

so , I try to make something like this . Inside the rectangle there is a text and a circle as a logo , so i make into a group , and the button state function ( click ) is working . However , I want that the hover function also work in group elements , but it doesn’t .

So , how to make the function also workig for group elements
Button Toggle1 - (19.8 KB)


You have absolutely no “hover” settings for the rectangle elements - so they are not going to work!
(See attached image below.)

You have to tell Hype what want You want it to do. You need to give the elements that You want to respond to events - such as a “hover” - the appropriate settings or scripts to trigger. Just because they are in a group does not change this situation.

So review the buttons in my example I previously provided and apply that to the rectangles.

(Ricky) #8

Oops ! Sorry for that

I put the hover settings already on the rectangle , buta as you can see the text and the circle is on the front of the rectangle . So , when I’m hovering on the rectangle it is blocked by the text and the circle , So how can I fix that

Button Toggle1 - (20.2 KB)


(Ricky) #10

yeahhh . thanks a lot man , for helping me ! Cheerss :raised_hands:


You’re Welcome!

Also please note:

  1. The “Groups” (“text1”, “text2”, & “text3”) have an ID assigned to them - they should not have one. The ID should be assigned to the corresponding “Rectangle” in each Group (and the ID erased from the ID field for that Group).

  2. Remove the (2) JavaScripts (“setBtnColor” & “setBtnState”) from each of these Groups - keeping of course the currently assigned JavaScripts for each Rectangle in each group.

(Ricky) #12

how can I change these keyframe from circular into cubic like on the right side ?


Answered your question (above) in this other post of yours (featuring the identical question)…