Flex 3: how can I simulate the clicking of a certain image (button)
Long story short - In order to make something work correctly, I need to simulate the user clicking on an image which doubles as a button and calls yet another function. I've tried simply calling the function, but it didn't work... for some reason, it only seems to work when the user clicks the button. Is it possible to 1) simulate clicks and 2) make the application think that the user clicks on a specific image?
Full story - My application (a scheduling application) allows the user to replace one student with another. In order to do this, the user can bring up a list of available students. Once the list is presented, and the user selects a new students name, that new name is supposed to replace the old name. Instead, the text box simply goes blank. Now, if I click a image (which acts like a button) 开发者_StackOverflowthat increases the length of a that scheduled activity by one day, the name appears for whatever reason. I've tried simply calling the function that increases the number of days, but it doesn't work. For some reason, it would appear that only the user clicking the image (button) seems to make the new user name show up in the text box. This is why I would like to simulate the user clicking the "increase by 1 day" image.
Yes, manually create and dispatch the click event.
Something along the lines of this:
var clickEvent : MouseEvent = new MouseEvent(MouseEvent.CLICK)
// set other relevant properties on the click event
myButton.dispatchEvent(clickEvent);
However, I suspect this is not the 'best' solution, but more of a work around. It sounds like there is some other problem with your code and how the text is put into the display when it is changed. Without seeing more code or knowing more about your apps layout, it's hard to say for sure.
精彩评论