tags:

views:

34

answers:

2

I create a custom component to override the linkButton to make it behave that if an exist value is found, it would shown as "Added".

By default the button label is "Add to cart", I could not make the button become "Added" after trying many trial and error on uHandler which I suppose, COMPLETE, ENTER_FRAME, CREATION_COMPLETE could not even update the label.

public class Btn extends LinkButton{
    public function Btn(){
      super();
      this.addEventListener(MouseEvent.CLICK, labelHandler);
      this.addEventListener(FlexEvent.INITIALIZE, loopArray);
      this.addEventListener(FlexEvent.PREINITIALIZE, cHandler);
      this.addEventListener(Event.COMPLETE, uHandler);
    }
...

private var disableLabel:int = 0;
    private function uHandler(event:Event):void {
     trace("creation");
     if(disableLabel == 1){
      super.label = "Already added";
      disableLabel = 0;
     }
    }

Please advice.

+1  A: 

You don't even have to extend the LinkButton class to change its label. You can just call :

linkBtnInstanceName.label = "Added";


You can use event listeners if it is in a Repeater. Check this code:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
    <mx:Repeater id="rp">
     <mx:dataProvider>
      <mx:Array>
       <mx:String>ASD</mx:String>
       <mx:String>QWE</mx:String>
       <mx:String>ZXC</mx:String>
       <mx:String>123</mx:String>
      </mx:Array>
     </mx:dataProvider>
     <mx:LinkButton label="{rp.currentItem}" click="onClick(event);"/>
    </mx:Repeater>
    <mx:Script>
     <![CDATA[
      private function onClick(event:MouseEvent):void
      {
       //this works
       LinkButton(event.currentTarget).label = "Clicked";
      }
        ]]>
    </mx:Script>
</mx:Application>
Amarghosh
it does not work that way, I believe dispatchevent was the only solution since the button was inside the repeater component
button is inside a repeater - thanks for mentioning that in the question.
Amarghosh
use `LinkButton(event.currentTarget).label = "Added";`
Amarghosh
A: 

I am the unknown (google), you just gave me the indirect idea using creationcomplete without the need to extend component, it did shown exactly what I need. Thanks!

I almost trying to shoot you off but manage to understand what you trying to explain after trial and error.

proyb2