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

What is Framer? Join the Community
Return to index
Kostantinos Frantzis
Posted Jul 24 - Read on Facebook

When importing from sketch or photoshop I have a ParentGroup which contains five subgroups (SubGroup1 to SubGroup5).

Is there a way to set up an event listener for each subgroup by looping through the parent group?

Similar to the demo bounce code.
This does not work for me:

// CODE
for (layerName in myLayers.ParentGroup) {

var layer = myLayers[layerName];

layer.on(Events.Click, function(event, layer) {
// Do something!!!
})
}

Thanks for any help.

12 Comments

Shamik Ray

I have a similar problem to solve - Have a grid of thumbnails as a gallery . Want to listen for clicks on each thumbnail and animate them accordingly. How should I go about it? Any help would be much appreciated :)

Алексей Кольченко

One of the option is using closure: http://codepen.io/akolchenko/pen/ILsGe

Koen Bok

You can also use this (or @) inside the event function. We bind it to the layer that calls it.

Kostantinos Frantzis

Koen thanks, can you give me an example?

Kostantinos Frantzis

cheers Koen

Shamik Ray

Thanks guys!

Kostantinos Frantzis

hey Koen. Still havent gotten this to work properly. Check the image to see the layer setup of my sketch file. I want a quick way to target individual subgroups at once. Like adding states and event listeners.

This works:
for (layerName in myLayers) {
var layer = myLayers[layerName];
layer.states.add({
pos1: {
x: 0
},
pos2: {
x: 465
},
pos3: {
x: 745
},
pos4: {
x: 1028
},
pos5: {
x: 1311
},
pos6: {
x: 1594
}
});
}

But what if I wanted to add layer states for layers in the base_units group only? Would be grateful if you could help.

Florian Pnn

Why you dont simply create an array at the beginning of your file with the different groups you want to target?

Adam Laskowitz

I am running into the same issue. Is there any documentation of the data structure for how layers are imported? I want to loop through my psd subgroups of a group - I can access them individually in Framer like PSD["someSubGroup"] but I can't do something like this PSD["group"].length and loop over that. How do we do this?

Adam Laskowitz

The solution!!!! PSDimport["_someGroupName"].subViews - this is an array of the groups inside the main group that you can iterate through. I found the answer in Christine Røde's post here. Thanks!

Adam Laskowitz

^ .subViews is deprecated FYI. .subLayers returns the same thing

Read the entire post on Facebook