This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Giovanni Caruso
Posted Dec 18 - Read on Facebook

Guys, having some annoying issue (noob staff) with if statement to enabling / disabling Click events on given layers. Hints? Thanks :)

This is an example:

# global var
enabled = 0

# button layers
buttonGreen = new Layer
x: 250
y: 100
width: 200
height: 200
backgroundColor: "green"

buttonYellow = new Layer
x: 100
y: 400
width: 200
height: 200
backgroundColor: "yellow"

buttonRed = new Layer
x: 400
y: 400
width: 200
height: 200
backgroundColor: "red"

# check var on start
print "enabled is " + enabled

# events
buttonGreen.on Events.Click, ->
enabled = 1
print "Clicked buttonGreen", "enabled is " + enabled

buttonYellow.on Events.Click, ->
enabled = 0
print "Clicked buttonYellow", "enabled is " + enabled

buttonRed.on Events.Click, ->
enabled = 0
print "Clicked buttonRed", "enabled is " + enabled

# logic enabled / disabled
if enabled == 0
buttonGreen.ignoreEvents = false
buttonYellow.ignoreEvents = true
buttonRed.ignoreEvents = true
else
buttonGreen.ignoreEvents = true
buttonYellow.ignoreEvents = false
buttonRed.ignoreEvents = false

4 Comments

Benjamin Den Boer

Hey Giovanni - are you looking to have a set of clickable buttons disable other buttons when 'active' / clicked? So, when clicking button A, button B&C become inactive until button A is made inactive again?

Giovanni Caruso

Yes, exactly. Noob stuff :)

Benjamin Den Boer

Hey Giovanni Caruso, here is a way you could go about this:
http://framer.link/cl.ly/Z1V7/buttonStates.framer.zip

Not the most elegant solution though, I think. 3 unique buttons are all clickable. When selecting one, it becomes active & remains clickable, while all others become inactive. When the active buttons becomes inactive again, all other buttons become clickable again. Hope this helps a bit.

Giovanni Caruso

Thank you Benjamin! I've already found a workaround: since I'm using transparent layers as buttons/active areas, the "layer.visible = false" does the job. Nonetheless, yours seems a most efficient implementation of the enable/disable state (it also prevents me to repeat the same blocks of code over the project). Time to study! :) P.S. I'd be happy to share the current state of the project, but framer.link gives back the same error: "The zip archive did not contain a framer project with the same name". Here's the link to the zip (still wip): http://goo.gl/rZVLro

Read the entire post on Facebook