"anchor" ?

I'm looking at the Tabs example right now - does anyone know what "anchor" and different values of anchor (e.g. "HEADER", "FOOTER") mean? I see the definition on the kinoma documentation but I still can't wrap my head around it. Thanks a lot!


  • Answer ✓

    Hello -

    Anchors are provided as a shortcut for accessing containers in the container hierarchy. The value of the anchor is completely arbitrary and up to the developer. In the Tabs example, the HEADER anchor identifies the header container in the hierarchy and the FOOTER anchor identifies the footer container. But these could be named TOP/BOTTOM, UPPER/LOWER or whatever makes sense to the developer.

    A primary benefit in using anchor references is that the code using anchors to access containers doesn't need to change if the container hierarchy changes. Containers in the container hierarchy can be traversed using a variety of methods. But some access methods break when the hierarchy changes. As a simple example, let's say the last child container in a hierarchy is a Label. You can set the label's string from the parent container as follows:

    container.last.string = "hello";

    But if you change the container hierarchy and add a new container/content after the label, the above code is no longer valid, since it assumes the last container is the label.

    If you instead associate an anchor reference with the label, the code can use the anchor to reference the label container:

    this.data.MY_LABEL.string = "hello";

    The code that sets the label's string using the anchor reference will continue to work even if you shuffle the container hierarchy.

    Hope this helps...

    Regards, Brian

  • thanks so much for your detailed explanation!

  • I notice that using anchor as a reference is slightly different, in that it's only a reference from a data object. i.e. you can't access container.MY_LABEL. But I've never been able to figure out how to change the way I write the code to use anchor. i.e. in the example above, what context is this and where does the data object come from?

    When would I want to use anchor instead of name? (and vice versa?)

Sign In or Register to comment.