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

What is Framer? Join the Community
Return to index
Benny Chew
Posted Aug 04 - Read on Facebook

I'm prototyping a tile based game (Bingo). Any ideas how to create a button event for let's say 25 tiles and being able to retrieve their ID (number from 0 to 24) on click. Not having to create separate 25 functions. I've tried a for loop, it worked, but I couldn't manage to retrieve the ID. I need this ID for an array I have. I couldn't find this in the examples, also searching was tricky to find. Thanks!

8 Comments

Min-Sang Choi

Try using “this”. It’ll tell current object’s properties.

//Object is an array, and syntax is under the loop

Object = new Layer blahblahblah

Obejct.on Events.Click,->

print(this.id)

Benny Chew

Thanks Min-Sang Choi will try!

Koen Bok

Here is a simple example: http://cl.ly/2P3x0K111F28

Benny Chew

Great! Thanks Koen Bok it worked. The Framer.js community is awesome! I didn't know you could pass the layer obj as a 2nd parameter in the click event.

Benny Chew

Just learned you can't use "id", it's a protected property perhaps. Have to use something like "buttonID" like in your example. Good to know.

Andreas Wahlström

you can also use this.buttonId instead of adding a clickedLayer parameter.

Ed Chao

here's an example of something somewhat similar. It's a photogrid populated with data from an object array. Data can be retrieved on an event. https://dl.dropboxusercontent.com/u/1916165/beacon_proto.framer/index.html

Benny Chew

Thanks for sharing Ed Chao, will definitely check it out!

Read the entire post on Facebook