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

What is Framer? Join the Community
Return to index
Nick Bewley
Posted Mar 27 - Read on Facebook

It looks like if you create a new Layer variable within an Event, that you cannot access that variable within other events.. How do people handle this?
_______________

For example:

button1.on Events.Click, ->
exampleLayer = new Layer

button2.on Events.Click, ->
exampleLayer.animate
properties: .....

Results in an error "Can't find variable: exampleLayer" ...

_______________

I realize that I can create the exampleLayer before and hide it, but are there any other approaches here?

2 Comments

Koen Bok

Initialize the variable outside of the function. Before your code add: exampleLayer = null

http://robertnyman.com/2008/10/09/explaining-javascript-scope-and-closures/

(See "Local Scope")

Nick Bewley

Awesome thanks!

Read the entire post on Facebook