Reputation: 993
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.
Upvotes: 0
Views: 350
Reputation:
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.
Upvotes: 0
Reputation: 59461
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>
Upvotes: 1