Jump to content

Adobe Flex and autoit

Recommended Posts

Yes, there is an example on the net but it has copy/paste errors and can be found here: AutoIT with Flex GUIs using the AS3 ExternalAPI

You will need eltorro's XMLDomWrapper UDF and place it into the AutoIt include directory.

Here is a debugged version:

#include <GUIConstants.au3>
#include <_XMLDomWrapper.au3> ;You can 

;Go into event capturing mode in stead of standard messaging mode
Opt("GUIOnEventMode", 1)

;Set busy for GUI event loop
global $busy = true

;External SWF File Name (assumed in same folder)
$swffile = "externalAPI.swf"

;Create the Shockwave Flash Object - this can contain Flex as well as Flash SWF Files
$oFlex = ObjCreate("ShockwaveFlash.ShockwaveFlash")

;Create the AutoIT GUI Window
$hModWnd = GuiCreate("Flex External API Demo", 400, 400, -1, -1, -1 )

;Create the ActiveX Container
$GUIActiveX = GUICtrlCreateObj( $oFlex, 0, 0 , 400, 400 )

;Set up event handling for Flex externalAPI calls
$SinkObject=ObjEvent($oFlex, "Flex_") ;

;Set up COM error handling
$oMyError = ObjEvent("AutoIt.Error","COMErrFunc")

;Initialize the Flex ActiveX
With $oFlex; Object tag pool
.Movie = FileGetShortName(@scriptdir & '\' & $swffile)
.ScaleMode = 3; 0 showall, 1 noborder, 2 exactFit, 3 noscale
.bgcolor = "#000000"
.Loop = False
.wmode = "transparent"; Opaque / transparent
.allowScriptAccess = "Always"

;Set close handler for AI GUI
GUISetOnEvent($GUI_EVENT_CLOSE, "closeTest" )


;Show the GUI
GUISetState ()

;Now call the Flex defined function AI3Call()
$oFlex.CallFunction('<invoke name="AI3Call"><arguments><string>Hello Flex!</string></arguments></invoke>')

;Loop until closed
while $busy

;The ExternalAPI Callback handler - the function that Flex will try to invoke is called FlashCall
;We have defined "Flex_" as a prefix here: $SinkObject=ObjEvent($oFlex, "Flex_") ;
Func Flex_FlashCall( $xml )
;Create an XML DOM Parser with the call XML string
_XMLLoadXML( $xml )

;Get the invoked function name
$invokedFunction = _XMLGetAttrib( "/invoke", "name" )
MsgBox( 1, "Invoked Function Name", $invokedFunction )

;Get the first (and in this case the only) parameter
$parameters = _XMLGetValue( "/invoke/arguments/string" )

MsgBox( 1, "We received a call from Flex", "Invoked Function: " & $invokedFunction & @CRLF & "Parameter: " & $parameters[1] & @CRLF & "Full XML:" & $xml )

;In theory, we can now set return value(s) in XML format - however, in Flex this doesn't seen to work.
;So we can send whatever series of values as a separate result function call back to Flex.
$oFlex.CallFunction('<invoke name="AI3CallReturn"><arguments><string>This is the return value for your call to FlashCall()</string></arguments></invoke>')

;Close GUI Event Handler
Func closeTest()
$busy = false

; COM error handler
Func COMErrFunc()

Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _
"err.description is: " & @TAB & $oMyError.description & @CRLF & _
"err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
"err.number is: " & @TAB & hex($oMyError.number, 8) & @CRLF & _
"err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
"err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
"err.source is: " & @TAB & $oMyError.source & @CRLF & _
"err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
"err.helpcontext is: " & @TAB & $oMyError.helpcontext _

Local $err = $oMyError.number
If $err = 0 Then $err = -1

SetError($err) ; to check for after this function returns

Flex Code:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()" width="400" height="400">
import mx.controls.Alert;
import flash.external.ExternalInterface;

private function init():void
ExternalInterface.addCallback( "AI3Call", AI3Call );
ExternalInterface.addCallback( "AI3CallReturn", AI3CallReturn );

private function AI3Call( message:String )
this.response_tx.text = message;

private function AI3CallReturn( message:String )
retval_tx.text = message;

private function MoreInfo():void
navigateToURL(new URLRequest("http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001971.html"), "_blank");

private function SendToAI3():void
ExternalInterface.call("CallAI3", Send_tx.text );

<mx:TextArea x="10" y="28" width="380" height="72" id="response_tx"/>
<mx:TextInput x="86" y="118" width="212" id="Send_tx" text="Hello AutoIT!"/>
<mx:Button x="306" y="118" label="Send" width="84" click="SendToAI3()"/>
<mx:Label x="10" y="120" text="Send Text" width="68"/>
<mx:Label x="10" y="10" text="Receive Text from Calling AI Function" width="380"/>
<mx:Text x="10" y="266" text="This example shows the basic comunication between a Flex Movie and an AutoIT3 ActiveX Container. It is more flexible than the Call() function and supports any combination of parameters sent back and forth using a simple XML format. This principle will also work for Flash 8 or higher movies, as it is pure ActionScript 3.0 on the SWF side. For more information on the AS3 externalAPI, click the link below." width="380" height="104"/>
<mx:LinkButton x="10" y="368" label="Adobe ExternalAPI LiveDocs" width="380" click="{MoreInfo()}"/>
<mx:TextArea x="10" y="172" width="380" height="73" id="retval_tx"/>
<mx:Label x="10" y="155" text="Returned XML from Call to AI" width="380"/>
<mx:HRule x="10" y="253" width="380" height="5"/>
<mx:HRule y="108" right="10" left="10"/>
<mx:HRule y="149" left="10" right="10"/>

--- TTFN

Link to comment
Share on other sites

  • 2 months later...
  • 5 months later...

Hi, this thread has been a huge help to me. Flash + autoit = beautiful guis and possibilites of animation. I've been working with flash and actionscript for a while and my coding there is basic at best. I'm going to use this a lot, and am trying to now actually. I'm getting caught up though. I don't understand exactly how autoit gets the message from flex. The FlashCall() function supposedly sends it, but I'm just not getting it. Can someone explain it please?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...