benbjohnson / melomel

External ActionScript Interface.
https://github.com/benbjohnson/melomel/wiki
Other
42 stars 8 forks source link

Better automation using standard Flex automation libraries #45

Closed laran closed 13 years ago

laran commented 13 years ago

There's one thing that's really difficult with Melomel. I have lots of objects with onChange handlers. The problem is that onChange only gets fired when a component's state changes "as the result of user interaction". In other words, an actual mouse click or keyboard input.

So, onChange handlers never fire when a selectedIndex is set on a combo box, or the text of a TextField is changed through Melomel. As has been mentioned elsewhere, file uploads are also tricky because of the FlashPlayer security rule requiring user input.

I've been reading about the standard Flex automation libraries (http://download.macromedia.com/pub/documentation/en/flex/2/at_api.pdf) and am wondering how they might be integrated to better support more natural automation.

Specifically what I'm thinking of is replacing this code in UI.as:

  ...
  component.dispatchEvent(event);
}

with something like this

  ...
        var replayEvent:AutomationReplayEvent = new AutomationReplayEvent();
        replayEvent.automationObject = component as IAutomationObject;
        replayEvent.replayableEvent = event;
        Automation.automationManager.replayAutomatableEvent(replayEvent);
}

If this works, it could make melomel much more seamless to integrate.

laran commented 13 years ago

So, I learned today that these automation libraries require a Flex Builder license. But I was able to use the Automation api.

This is what Melomel.UI does by default in the interact method:

component.dispatchEvent(event);

Using this instead uses the automation library instead

replayEvent.automationObject = component as IAutomationObject;
replayEvent.replayableEvent = event;
Automation.automationManager.replayAutomatableEvent(replayEvent);

In either case they behavior is exactly the same. I think the automation version though should get around some issues with Flex requiring actual user interaction for certain events to fire (i.e. change).

I'll be playing around with this some because not being able to trigger change events is a real pain for me.