开发者

FLEX button to trigger event continiously when pressed... not once!

I'm wondering if there's a way to configure a FLEX button so it behaves like a push开发者_高级运维 button...


<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


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()"/>


<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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜