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

What is Framer? Join the Community
Return to index
Alberto Guzmán
Posted Sep 08 - Read on Facebook

Hi Friends,

Quick question:
I have a layer (Layers.Pic) of back to back square sublayers and I would like to:
1. get an array of all the subLayers
2. Access the topmost layer, and send it to the back

I have this but it won't work :(

subLayerArr = Layers.Pic.subLayersByName()
subLayerArr[0].sendToBack()

I keep getting this error:
'undefined' is not an object (evaluating 'subLayerArr[0].sendToBack')

Any chance anybody knows what's up?

Thanks for the help :)

10 Comments

Johannes Eckert

you did subLayeryByName() but didn't specify a name. I think you want to use subLayers()

Alberto Guzmán

Johannes thanks for that tip! I used subLayersByName() only because the doc said it explicitly returned an array. I changed my code to:

subLayerArr = Layers.Pic.subLayers
subLayerArr[0].sendToBack()

Although there is no error, the topmost sublayer still doesn't get sent back :(

Johannes Eckert

that's maybe because the first layer in the array is NOT your topmost layer. in fact, I believe it should be the last one subLayerArr[subLayerArr.length-1]

Johannes Eckert

(that's because layers get stacked ontop of each other when they are created)

Benjamin Den Boer

Hey Alberto Guzmán, I created a quick sample document to clarify how to do this using roughly the same set-up as yours.

Download the .framer here: http://cl.ly/XM6W

The gist of it is this:
1. You can give all subLayers the same "name" property.
2. You then create an array of all of these subLayers by targeting this name with subLayersByName("name")
3. You can now target your subLayers via indeces of your array variable. (myArray[0] etc.)

Alberto Guzmán

Johannes Eckert Benjamin Den Boer This really cleared things up. Thanks so much for the help, I really appreciate it!

Alberto Guzmán

Johannes Eckert Benjamin Den Boer One last question:
I have those two lines of code attached to a click event. The first layer gets sent to the back on the first click only, but not any other subsequent click.

subLayerArr = Layers.Pic.subLayers

Layers.Decline.on Events.Click, ()->
subLayerArr[subLayerArr.length - 1].sendToBack()

Any thoughts?

Johannes Eckert

It sounds like you want to send the layer you clicked on to the back? Can you do this.sendToBack()?

Alberto Guzmán

Johannes Eckert Actually the Click event is attached to a button called "Layers.Decline" which controls the subLayerArr which is just Layers.Pic.subLayers

Alberto Guzmán

Johannes Eckert Benjamin Den Boer Thanks again for the help! I got around to finishing up what I started you can check it out here -> https://pbs.twimg.com/tweet_video/BwwPRA1CAAAmQ7_.mp4

The main issue was that I wasn't aware that sending a layer back didn't actually send it back in the array.

Read the entire post on Facebook