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

What is Framer? Join the Community
Return to index
Paul Kooi
Posted Jan 24 - Read on Facebook

Having some trouble and would love help from some of you ninja's out there... I'm trying to write a simple conditional where on Click framer checks to see if the current object, in this case layerA has a state of "default". If the state is "default" do X, else do Y...

When I run it... it always does Y... seems like no matter what the state is... it always switches to "C"

layerA.onClick ->
if layerA.state = "default"
layerA.states.switch("B")
else layerA.states.switch("C")

4 Comments

Björn Mußmann

Does

layerA.onClick ->
if layerA.states.current.name == "default"
layerA.stateSwitch("B")
else
layerA.stateSwitch("C")

do the job?

Paul Kooi

thank very much
I tried.current.name but only used one = sign... I always forget to double them up

Andrew Liebchen

Coffeescript is helpful here in that you can write `is` which will compile to `==`. Never forget that double equal again!

Sam Olaogun

For a simple conditional like this, you can cut down on code with a ternary operation. (layerA.states.switch layerA.states.current.name is 'default' ? 'B' : 'C') should do the trick. Plus, Utils.stateCycle might be useful here.

Read the entire post on Facebook