All 2 entries tagged Air

View all 29 entries tagged Air on Warwick Blogs | View entries tagged Air at Technorati | There are no images tagged Air on this blog

March 08, 2009

More AIR web automation – styles and dispatching mouse events

Follow-up to Automating web workflow in Adobe AIR from Transversality - Robert O'Toole

More experiments with creating automated workflows using the AIR html component. The following code gets the dom document once the html has loaded. It then gets a reference to a span in the document called 'edittool'. Once an element is referenced as a Flex Object, we can call native javascript methods on it. In this case, I give it a yellow dashed border. I then get hold of the A element that is it's child, and dispatch a mouse over event to it, causing its mouseover handler to be called. The result is that the edit menu appears.

private function initDomWindow(event:Event):void {
this.domWindow = event.currentTarget.domWindow;
var edittool:Object = domWindow.document.getElementById("edittool");
edittool.style.borderColor = "yellow";
edittool.style.borderStyle = "dashed";
var overevent:Object = domWindow.document.createEvent("MouseEvents")
overevent.initEvent("mouseover", true, true);
var a:Object = edittool.getElementsByTagName('A')[0];
a.dispatchEvent(overevent);
}

The html mxml tag is configured as:

<mx:HTML id="htmlTranslate" width="800" height="800" location="{this.url}" complete="initDomWindow(event)"/>



March 06, 2009

Automating web workflow in Adobe AIR

This entry was created using an AIR based browser.

Yes, it's possible. I wrote a simple AIR app that signs me in to Warwick Blogs by loading the login page into an AIR app, populating the login form fields, and submitting. It's also possible to call javascript methods in the page. Here's the code:

<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="1024" height="768">

<mx:Script>
	<![CDATA[
 
			import mx.controls.Alert;
	
			private var domWindow:Object;
			private var blnAlertThrown:Boolean = false;
			private var load:int = 0;
						
	        private function initDomWindow(event:Event):void {
			if(load == 0)
			{
			load++;
	        domWindow = event.currentTarget.domWindow;
        	getElementFromHTML("userName").value = "myusername";
        	getElementFromHTML("password").value = "mypassword";
        	domWindow.document.forms[0].submit();
			}
			else
			{
				load++;
			}        	
	        }

	        private function getElementFromHTML(elementName:String):Object {
				var arrayContainingAllFoundElements:Object = domWindow.document.getElementsByName(elementName);
				return arrayContainingAllFoundElements[0];	
	        }
 	
	]]>
</mx:Script>

<mx:HTML id="htmlTranslate" x="10" y="84" location="http://blogs.warwick.ac.uk/blogbuilder/admin/create/plainEntry.spr?blog=094d4021fb4dbd6d00fb4de01b490001&amp;newPermissions=Anyone&amp;newCommentPermissions=Anyone" complete="initDomWindow(event)"/>
	
</mx:WindowedApplication>