开发者

How do I programmatically trigger a mx:Button click event?

开发者 https://www.devze.com 2023-01-03 17:42 出处:网络
Consider the following mx:Button: <mx:Button click=\"doSomething()\" id=\"myButton\"/> Is there some way to programmatically emulate the user clicking the button?

Consider the following mx:Button:

<mx:Button click="doSomething()" id="myButton"/>

Is there some way to programmatically emulate the user clicking the button?

One obvious way to do it would si开发者_如何学Cmply be to call doSomething() which would give the same end result as clicking the button. But I'm specifically looking for ways to emulate the click -- that is something along the lines of myButton.click() (if that should have existed).


The Button class dispatches events just like any other piece of ActionScript code: it uses the dispatchEvent method of the IEventDispatcher interface. You could invoke this yourself using this code:

myButton.dispatchEvent(new MouseEvent(MouseEvent.CLICK));

0

精彩评论

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