tags:

views:

224

answers:

3

Hello. I'm wondering if there's a way to configure a FLEX button so it behaves like a push button...

+3  A: 

If you just need it to toggle (which is how a pushbutton behaves), set its toggle property to true.

<mx:Button label="Button Test" toggle="true"/>

If this is not what you mean, be more specific in your question.

EDIT: Since you refined your question, I would suggest you make a handler for the mouseDown event of the button, which starts a method running, and make a mouseUp handler that stops the method from running. Or better yet, have it set or unset a variable, which is tested in the updateDisplayList() method. Like so:

private var _runButtonStuff:Boolean = false;


override protected function updateDisplayList(width:Number, height:number) : void {
  super.updateDisplayList(width,height);
  if (_runButtonStuff) {
    doStuff();
  }
}

private function doStuff() : void {
  // do some stuff  
}

private function buttonIsDown() : void {
  _runButtonStuff = true;
}

private function buttonIsUp() : void {
  _runButtonStuff = false;
}

and the button looks like this:

<mx:Button text="Run Something" mouseDown="buttonIsDown()" mouseUp="buttonIsUp()"/>
Robusto
What I need is the button to behave like a push button... I mean... when you push the button... it has to trigger continiously a push event or something like that... :)
Jean Paul
@user352353: OK, edited to show how to do this. It's important to use updateDisplayList in this way so that things that change will appear to change.
Robusto
I think this will work only when the mouse over the button is UP. I think either i missed out the OP question or either he was not clear... pretty good way though and nice riposte Robusto
Vinothbabu
@Vinothbabu: This will work when the mouse button is down. If he wants it to stay pressed, he should use the toggle property and change the test in updateDisplayList to check whether the button's toggle property is true or false, and of course give that button an ID then, etc.
Robusto
A: 
<mx:Button label="Button Test" toggle="true" click="yourMethodName()"/>

public function yourMethodName():void {
    var evt:someEventName = new someEventName(someEventName.TYPE);
    dispatchEvent(evt);        
}

Now when you listen to this event again, call the same method name again through addEventListner. It will keep on firing the same event for ever.

I have a question, on what scenario you want to apply this. You can either go by EventDispatcher or some ActionScript code which will keep on firing the same method name until the equation is solved.

Depending upon your requirement you can go. I would suggest event driven, as it would be easier to manage.

Vinothbabu
+2  A: 
<mx:Button buttonDown="trace('ankur')" autoRepeat="true"/>

to make a flex button to receive contiuous event happening, use the autoRepeat property with buttonDown event, note the click property will no work,

put this tag in ur application, run it,

i hope , this is wht u were luking for

thanx

Ankur Sharma

Ankur Sharma