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

What is Framer? Join the Community
Return to index
Dan Clarke
Posted Aug 19 - Read on Facebook

Hi Gang

I have a layer which I want to repeatedly switch between states (default, b) when it's clicked. and then when it's clicked again, go to the default state. for all I can tell this should work? but when clicking again it just layers up the Utils.Interval.

It's like I need to cancel that interval somehow?

http://share.framerjs.com/mlacgxact9r1/

13 Comments

Joshua Tucker

Hey Dan! You need to store the interval in a variable and then clear it when and where you want to.

interval = Utils.interval 0.5, ->
clearInterval interval

Dan Clarke

Thanks Joshua Tucker. that makes sense. i'm not familiar with the clear function?

Joshua Tucker

Of course! clearInterval is the Coffeescript way (writing out wise) of doing window.clearInterval() - https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/clearInterval

Utils.interval is a function that the Framer guys created to make it more user-friendly to set intervals. In the source, it's using window.setInterval - https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval

Dan Clarke

thanks Josh, makes sense. but the syntax doesn't seem to be working...

clearInterval myInterval

Joshua Tucker

Make sure your interval variable is available in both scopes. Declaring it the first time inside the if statement locks it in there. myInterval is undefined in the else if statement if the variable isn't available in its scope. Making it global gets it working.

Dan Clarke

boom! that's it. schoolboy error. y'know I coded in c++ back at uni so I should remember the simple things like scope but it's been a while.....

Dan Clarke

thanks so much Joshua Tucker

Joshua Tucker

Dan Clarke Right on man! It's all good – we're all learning here :). Cheers! Always happy to help.

Dan Clarke

i wonder if anyone else has 'learning a new language' difficulties. I've found a few times that the syntax in java/coffee script has taken some adjustment where I think I could "just do it" in c++ but not in coffee

Joshua Tucker

It definitely has a learning curve. I took one programming language in college but it didn't stick, at least not to my knowledge of how I began learning JS/CS. Syntax comes with practice, a lot of reading, and just straight up tinkerin'! Don't be disheartened friend :). I recommend searching the group and online for Framer tutorials or Coffeescript stuff. Lots of great resources that expedite your ability to be proficient. Well worth it.

Dan Clarke

Thanks man. Yeah there has been lots of hacking so far and this group has been amazing! I've done pretty well with modules and some more complex stuff and then it's just the 'simple' stuff that's easy to forget

Dan Clarke

I intend to share some of my completed works on here at some point....

Joshua Tucker

That would be very cool! We'd love to see them. Yeah, the simple stuff gets the best of all of us. Story of my life! Haha.

Read the entire post on Facebook