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 subLayers2. Access the topmost layer, and send it to the back
I have this but it won't work :(
subLayerArr = Layers.Pic.subLayersByName() subLayerArr.sendToBack()
I keep getting this error:'undefined' is not an object (evaluating 'subLayerArr.sendToBack')
Any chance anybody knows what's up?
Thanks for the help :)
you did subLayeryByName() but didn't specify a name. I think you want to use subLayers()
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.sendToBack()
Although there is no error, the topmost sublayer still doesn't get sent back :(
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]
(that's because layers get stacked ontop of each other when they are created)
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 etc.)
Johannes Eckert Benjamin Den Boer This really cleared things up. Thanks so much for the help, I really appreciate it!
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()
It sounds like you want to send the layer you clicked on to the back? Can you do this.sendToBack()?
Johannes Eckert Actually the Click event is attached to a button called "Layers.Decline" which controls the subLayerArr which is just Layers.Pic.subLayers
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.