Sign in to follow this  
Followers 0
Errol

Embedded Flash not able to read XML

10 posts in this topic

Hello,

I've been working on making a tutorial program that would overlay another program and prompt the student.

Trying to make my program more extensible, I wanted the flash file to read in an XML file.

The .swf on its own will happily read in the XML file. :)

The .swf embedded in AutoIT will not read the XML file. <_<

I have attached a zipped file which should show my problem.

helpme.zip

In the zip file are:

  • Help_Tutorial_Shell.au3 - AUTOIT file
  • help_me_xml.swf - flash file it embeds
  • test.xml - XML file the flash file tries to read
  • transparent_EFEFDE.gif - a gif used for transparency
The AutoIT code, in case you don't want to go to the trouble of downloading, looks like this:

#include <GUIConstants.au3>

Opt("GUICoordMode", 1)          ;1=absolute, 0=relative, 2=cell
Opt("GUIOnEventMode", 1)        ;0=disabled, 1=OnEvent mode enabled
Opt("GUIResizeMode", 0)         ;0=no resizing, <1024 special resizing

; Global Variables
Global _
    $DeskW = @DesktopWidth, _
    $DeskH = @DesktopHeight, _
    $GUIW = 600, _
    $GUIH = 200

; mGUI = main GUI
$mGUI = GUICreate("Tutorials", $GUIW, $GUIH, 0, 0, -1 ,BitOr($WS_EX_LAYERED,$WS_EX_TOOLWINDOW,$WS_EX_TOPMOST))
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
GUISetState(@SW_SHOW,$mGUI)

; Make mGUI transparent
GUICtrlCreatePic("transparent_EFEFDE.gif", 0, 0, $GUIW, $GUIH)
GUICtrlSetState( -1, $GUI_DISABLE)

; Create Flash Object
$swfObj = ObjCreate("ShockwaveFlash.ShockwaveFlash")
$swfActiveX = GUICtrlCreateObj( $swfObj, 0, 0 , $GUIW, $GUIH)
$swfObjEvents = ObjEvent($swfObj,"_fscommand")

; Configure Flash Object (Make as Function)
With $swfObj 
    .Movie = @WorkingDir & '/help_me_xml.swf'
    .ScaleMode = 3 ;0 showall, 1 noborder, 2 exactFit, 3 noscale
    .bgcolor = "#EFEFDE"
    .Loop = True
    .WMode = "transparent"
    .allowScriptAccess = "Always"
EndWith
GUISetState(@SW_SHOW)

; MAIN LOOP
While 1
    Sleep(10)
WEnd

; Functions
Func _fscommand($type,$command,$arguments)
    If $type = "fscommand" Then
        If $command = "button" Then
;           $swfObj.SetVariable("subtitle", "[" & @UserName & "] " & $arguments)
        EndIf
    EndIf
EndFunc ;==>FSCommand

; Quit the program
Func _Quit() 
    GUIDelete()
    Exit
EndFunc ;==>_Quit

And for further fun, here's the flash actionscript I used to load in the XML. May be difficult to understand without the actual fla, sorry.

// eventually make generic
xmlFile = "test.xml";

page_num= 0; // which page we're on ... zero indexed of course

subtitle = "Click button to load XML file"; // initialize textbox

// MOUSE
//////////////////////////////////////////
next_button.next_button.onRelease = function() {
    xmlData = new XML();
    xmlData.ignoreWhite = true;
    xmlData.onload = loadXML;
    xmlData.load(xmlFile);
    fscommand("button", "You clicked it")
};

function loadXML(loaded) {
    if (loaded) {
        xmlNode = this.firstChild;
        type = [];
        voice = [];
        txt = [];
        swf = [];
        
        total = xmlNode.childNodes.length;
        for (i=0; i<total; i++) {
            type[i] = xmlNode.childNodes[i].attributes.type;
            voice[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
            txt[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
            swf[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
        }
        init();
    } else {
        subtitle = "file not loaded!";
    }
}

function init() {
    prev_button._visible = false;
    subtitle = txt[page_num];
}

If you made it this far, thanks in advance! :P

Share this post


Link to post
Share on other sites



Using filemon, I foudn out somthing interesting...

When the flash object is ran from the ebmbeded autoit windows it tries to open the text.xml file in the directory behind it. For example I ran the script from a folder "C:\Documents and Settings\<username>\Desktop\helpme\Help_Tutorial_Shell.au3" and filemon reported that it tried to open "C:\Documents and Settings\<username>\Desktop\test.xml" but failed becuase it doesn't exist. I copied the text.xml to the desktop and it worked!

Try making your flash code reference an absolute path instead of a virtual one.

Share this post


Link to post
Share on other sites

Using filemon, I foudn out somthing interesting...

When the flash object is ran from the ebmbeded autoit windows it tries to open the text.xml file in the directory behind it. For example I ran the script from a folder "C:\Documents and Settings\<username>\Desktop\helpme\Help_Tutorial_Shell.au3" and filemon reported that it tried to open "C:\Documents and Settings\<username>\Desktop\test.xml" but failed becuase it doesn't exist. I copied the text.xml to the desktop and it worked!

Try making your flash code reference an absolute path instead of a virtual one.

Bonus! :)

Thank you very much! I will take a look at that. <_<

This forum is great. That was my first post because I've been able to find almost all of my questions on here.

Thank you once again.

Share this post


Link to post
Share on other sites

Bonus! :)

Thank you very much! I will take a look at that. <_<

This forum is great. That was my first post because I've been able to find almost all of my questions on here.

Thank you once again.

flash + autoit = awesome. Especially with the fscommand actionscript. I just finished making a complete GUI for my company's users using this method. Works like a charm.

Share this post


Link to post
Share on other sites

flash + autoit = awesome. Especially with the fscommand actionscript. I just finished making a complete GUI for my company's users using this method. Works like a charm.

Wth I didn't know you can use those together. <_<

Where can I read about this?


Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

do a search on the forums for fscommand. I had a thread going about a year ago about it. It works the same as using fscommand with a javascript page.

Anything else you need to know, just ask. I've got the method down.

I've even got a client autoit and server autoit communicating with eachother with the flash xmlsocket object.

Edited by Jud420

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Here is a basic example of an embedded flash object:

#include <guiconstants.au3>

$mGUI = GUICreate("Tutorials", 600, 300, 0, 0, -1 )
GUISetBkColor (0x000000)
GUISetState(@SW_SHOW)

; Create Flash Object
$swfObj = ObjCreate("ShockwaveFlash.ShockwaveFlash")
$swfActiveX = GUICtrlCreateObj( $swfObj, 0, 0 , 600, 300)

; Configure Flash Object (Make as Function)
With $swfObj
    .Movie = @ScriptDir & '/candleFlame.swf'
    .ScaleMode = 3 ;0 showall, 1 noborder, 2 exactFit, 3 noscale
    .bgcolor = "#000000"
    .Loop = True
    .WMode = "transparent"
    .allowScriptAccess = "Always"
EndWith

; MAIN LOOP
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
    Sleep(10)
WEnd

candleFlame.zip

Edited by weaponx

Share this post


Link to post
Share on other sites

do a search on the forums for fscommand. I had a thread going about a year ago about it. It works the same as using fscommand with a javascript page.

Anything else you need to know, just ask. I've got the method down.

I've even got a client autoit and server autoit communicating with eachother with the flash xmlsocket object.

Sounds awesome! :P

For some reason I keep missing a part of the message I send using the AutoIt's TCP functions.. When using Flash it works perfect so I guess this is just what I need. <_<

I always thought it wouldn't be possible to make a server using flash, but with a little help from AutoIt it sure seems it can. :)

Great I'll take a look at this as I am really into ActionScript aswell, but it seems your script is in AS 2.0? In 3.0 everything is different so I've been too lazy to work on anything in flash recently. :)


Share this post


Link to post
Share on other sites

Yeah its all in 2.0. I'm sticking to what I know for now, until I have some time to sit down and learn 3.0, which looks to be MUCH more feature-rich. The server app that I'm using actually uses a simple java tcp server that simply repeats all messages it receives to all sockets connected, then i use the xmlsocket to send messages that trigger functions in the server/client apps. works pretty outstandingly.

Share this post


Link to post
Share on other sites

Yeah it sure sounds nice! I'm just curious as to how to send or listen to the sockets that are opened by AutoIt. Since you can't listen to ports with XMLSockets??? Well I'd sure be interested in learning more about this, also what I was wondering is if there is a protection in the flash to turn off the fscommand incase it's a "hack" for example a game.. If the flash document (.swf) is a flash game and the AutoIt is used as a wrapper for it and then using the setVariable fscommand you could easily get infinite gold etc. if you just know the variable names....

Well enough about that, what I'd really like to know is about listening to the sockets and sending data through them, maybe I could add you on a IM software if you use MSN for example so I could ask you a few questions about it real-time if it's fine with you.

And yeah I know AS 2.0 too, but I kind of don't want to use it since 3.0 is out. I'd like to use the latest one out, for now I haven't started practicing AS 3.0 yet, hopefully I will soon, this sure gives me encouragement to continue on flash again. <_<


Share this post


Link to post
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
Sign in to follow this  
Followers 0