;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 = @scriptdir & ‘\’& $swffile; .ScaleMode = 3; 0 showall, 1 noborder, 2 exactFit, 3 noscale .bgcolor = "#000000"; .Loop = False .wmode = "Opaque"; Opaque / transparent .allowScriptAccess = "Always" EndWith ;Set close handler for AI GUI GUISetOnEvent($GUI_EVENT_CLOSE, "closeTest" ) ;Show the GUI GUISetState () ;Now call the Flex defined function AI3Call() $oFlex.CallFunction(’Hello Flex!’) ;Loop until closed while $busy sleep(10) WEnd ;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 & @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(’This is the return value for your call to FlashCall()’) EndFunc ;Close GUI Event Handler Func closeTest() $busy = false GUIDelete() EndFunc ; 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 EndfuncComplete Flex Code
Trackback from your site.