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

What is Framer? Join the Community
Return to index
Joseph Brick
Posted Nov 09 - Read on Facebook

Extending the Layer class?

Assume that I want an object that consists of an outer layer which is the parent of multiple other layers. I want this object to respond to events (click, resize) as well as store values, so making it a class seems like a good idea.

My class currently looks roughly like this:

class myObject
constructor: ()->
@image=new Layer
@title=new TextLayer
@outerLayer=new Layer
@[email protected]
@[email protected]

This works fine, but when I want to - say - make an instance of this class be the child of another layer, I have to do this:

o=new myObject
otherLayer.addChild(o.outerLayer)

...when I really want to say:

o=new myObject
otherLayer.addChild(o)

Or if I want its size, I have to say o.outerLayer.size rather than o.size, etc.

To make this work how I want it to work, I'm assuming I need my class to extend the Layer class, and have the instance itself assume the role of this outerLayer hack that I've put in. But Google has failed me in this regard.

With those intentions in mind, what would my class above look like as a subclass of Layer? Or is there another way of achieving the same thing?

7 Comments

Joseph Brick

Oh, and if someone could tell me how to add indention to a FB post, that would be great.

Derek Nguyen

You just need to extends Layer:
```
class OuterLayer extends Layer
--constructor: (options={}) ->
----# declare your custom outerLayer's default value here
----super options
----# do your other thing, attach events, etc.

```

And no, no way to add indentation to fb post/comment. Which is one of the reasons I wish this community to move somewhere else!

Joseph Brick

Hi Derek - I don't follow. I want to use the class instance itself as the outer layer, so I'd have only two layers inside of it, @image and @title. In the constructor I want to do the following:

Joseph Brick

* set the size of the instance

Joseph Brick

* make @image and @title children of this instanc

Joseph Brick

I figured it out:

Joseph Brick

class foo extends Layer
constructor:() ->
@title=new TextLayer
@poster=new Layer
super
this.width=200
this.height=100
@title.parent=this
Post like your parents just joined this group

Read the entire post on Facebook