I am creating a textbutton using actionscript.
the code is given below.
public function createTextButton(parentId){
var mytext:TextField = new TextField();
mytext.x = 478;
mytext.y = 225;
mytext.height = 20;
var format:TextFormat = new TextFormat();
format.font = "Hitchcock";
format.size = 20;
mytext.defaultTextFormat = format;
mytext.textColor = 0xffffff;
mytext.htmlText = '<a href="j#" >Click Here</a>';
mytext.addEventListener(MouseEvent.CLICK,paginationLinkClicked);
mytext.addEventListener(MouseEvent.MOUSE_OVER,mouseOverButton);
mytext.addEventListener(MouseEvent.MOUSE_OUT,mouseOutButton);
parentId.addChild(mytext);
}
Now i want the click event of this button to be handled in my event handler function only. It should not navigate away to the ‘href’ source given upon clicking.
How can i achieve that.
Add
event.preventDefault();in your event handler once you’ve finished your custom handling.From the adobe docs: http://livedocs.adobe.com/flex/3/langref/flash/events/Event.html
Update:
preventDefault won’t work in this case.
You’ll need to add a
linkevent handler and prefix the url withevent:. Here’s a simplified version of your code:TextArea docs on the link event handler: