INCLUDE_DATA

Decorated LinkBar component

In my last article I demonstrated how to create like picnik.com TabNavigator. Now, it is time to move forward and try to create decorated LinkBar component. In this article I will show how to add triangle garland under selected item and move it when you change selected item.

So, lets extend LinkBar bass class and add garland under selected item.

public class ExtendedLinkBar extends LinkBar

Because we need to add garland under LinkBar component we need to create UIComponent type variable which will contain graphics.

private var uiComponentContainer    : UIComponent = new UIComponent();

In UIContainer we can draw anything we like, even place images, icons etc. Procedure which draw garland may look like below.

private function CreateGarlandContainer():  void {

            uiComponentContainer.name = "bottomGarland";

            uiComponentContainer.graphics.beginFill(GarlandBgColor,1);
            uiComponentContainer.graphics.lineStyle(2, GarlandBgColor, 0, false, "normal", "square", "miter", 1);

            uiComponentContainer.graphics.moveTo(0, 0 );
            uiComponentContainer.graphics.lineTo(GarlandWidth /2, GarlandHeight);
            uiComponentContainer.graphics.lineTo(GarlandWidth, 0);
            uiComponentContainer.graphics.lineTo(0, 0);                

            uiComponentContainer.graphics.endFill();          

            uiComponentContainer.graphics.lineStyle(3, GarlandShadowColor, 0.3, false, "normal", "round", "bevel", 0);
            uiComponentContainer.graphics.moveTo(0, 0 );
            uiComponentContainer.graphics.lineTo(GarlandWidth/2, GarlandHeight);
            uiComponentContainer.graphics.lineTo(GarlandWidth, 0);

            uiComponentContainer.graphics.lineStyle(2, GarlandBgColor, 1, false, "normal", "round", "miter", 1);
            uiComponentContainer.graphics.moveTo(0, 0 );
            uiComponentContainer.graphics.lineTo(GarlandWidth, 0);

            GarlandCreated  = true;            

}

Since our component contains garland all we need is add container to display list. To do so, you need to call addChild function and refresh linkbar size by calling setActualSize function.

this.parent.addChild(uiComponentContainer);

this.setActualSize (this.getExplicitOrMeasuredWidth(),
                               this.getExplicitOrMeasuredHeight());

Please notice I do not add UIComponent container to bass LinkBar class, instead of this I am adding to LinkBar parent. Purpose is quite simple, if you add UIComponent container it can be overlapped by other components linked to LinkBar (like Canvas, VBox). Remember to refresh LinkBar class to get updated size.

To achieve nice dynamic garland move behavior I calculate distance between previous and currently selected link bar button and move garland on time event.

private function timerHandler(event:TimerEvent):void {

  var GarlandXPos    : int  = GarlandNewXPos - (GarlandXStep * (GarlandMoveSteps - GarlandMoveTimer.currentCount) );

  uiComponentContainer.move( GarlandXPos , this.height );

}

Result you can see beneath. Right click on mouse if you want to see the code.

Comments

4 Responses to “Decorated LinkBar component”

  1. migchulo on June 16th, 2009 1:42 pm

    I am trying to use the ExtendedLinkBar in my application and I noticed a bug with it. If you maximize or minimize the browser, the Garland will disappear. Have you noticed this?

  2. admin on June 18th, 2009 8:48 am

    Yes, indeed. There is a need to extend this component and some extra features like recalucation garland postion on resize event.
    Maybe when I find some spare time I will do it. So far a summer holiday is on the corner…

  3. admin on June 18th, 2009 2:56 pm

    Ok, I added handler for Resize event.

    this.addEventListener(Event.RESIZE, onResizeEvent);

    Now, garland is moving to last postion when you change window size.

  4. handoyo on July 25th, 2009 4:15 am

    Thanks for the component..

Leave a Reply

You must be logged in to post a comment.