Air App Dilema

Hi All,

Apologies if I haven’t posted this in the right spot, but I couldn’t see anywhere specific to Air Apps.

I’ve been racking my brain for weeks now trying to work out how to do the following. I can do some of it in Flash and some of in Flex, but I can’t do it all in Flex which is frustrating.

In a nutshell, I want to create an Air App that will allow me to load an XML file from:
[SIZE=2]
File.userDirectory

and then display images or SWF’s based on the XML data:

============

<?xml version=“1.0” encoding=“utf-8”?>
<GALLERY>
<IMAGE TITLE=“shop”>test_4.swf</IMAGE>
</GALLERY>

===========

In Flex 3 I can get the XML file loading from the userDirectory no problem, but I can’t work out how to code it to display the images on the stage.

In Flash I can get the XML file loading from the apps installation directory only, but I can display the images on the stage.

Here are the two lots of code:

FLASH (Note: I have a few movieclips holding the images)

var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest(“example.xml”));
myLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void {
myXML = new XML(e.target.data);
//trace(myXML.IMAGE);
for (var i:int = 0; i<myXML..length(); i++) {
trace("My image number is " + (i+1) + ", it’s title is " + myXML.IMAGE
.@TITLE + " and it’s URL is " + myXML.IMAGE*);
var url:URLRequest = new URLRequest(myXML.IMAGE*);
var loader:Loader = new Loader();
loader.load(url);
switch (i) {
case 0 :
trace(0);
mc_container_0.addChild(loader);
break;
case 1 :
trace(1);
mc_container_1.addChild(loader);
break;
case 2 :
trace(2);
mc_container_2.addChild(loader);
break;
default :
//trace(“Not 0, 1, or 2”);
}
}
}

=======================

and:

FLEX 3

=======================

[SIZE=2][LEFT]<?xml version=“1.0” encoding=“utf-8”?>[/LEFT]
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][LEFT]<mx:WindowedApplication[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] xmlns:mx="[/SIZE][SIZE=2][COLOR=#990000][SIZE=2][COLOR=#990000]http://www.adobe.com/2006/mxml[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]" layout="[/SIZE][SIZE=2][COLOR=#990000][SIZE=2][COLOR=#990000]vertical[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]"
width="[/SIZE][SIZE=2][COLOR=#990000][SIZE=2][COLOR=#990000]768[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]" height="[/SIZE][SIZE=2][COLOR=#990000][SIZE=2][COLOR=#990000]1366[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]" xmlns:comp="[/SIZE][SIZE=2][COLOR=#990000][SIZE=2][COLOR=#990000][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]" xmlns:fmtComp="[/SIZE][SIZE=2][COLOR=#990000][SIZE=2][COLOR=#990000]fmtComps.[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]"
creationComplete=“readXMLContent();” paddingLeft="[/SIZE][SIZE=2][COLOR=#990000][SIZE=2][COLOR=#990000]0[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]" paddingRight="[/SIZE][SIZE=2][COLOR=#990000][SIZE=2][COLOR=#990000]0[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]" paddingTop="[/SIZE][SIZE=2][COLOR=#990000][SIZE=2][COLOR=#990000]0[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]" paddingBottom="[/SIZE][SIZE=2][COLOR=#990000][SIZE=2][COLOR=#990000]0[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]" backgroundColor="[/SIZE][SIZE=2][COLOR=#990000][SIZE=2][COLOR=#990000]#ff00ff[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]"[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#006633][SIZE=2][COLOR=#006633]<mx:Script>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]<![CDATA[
[/SIZE][SIZE=2][COLOR=#0033ff][SIZE=2][COLOR=#0033ff]import[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] mx.controls.Alert;
[/SIZE][SIZE=2][COLOR=#0033ff][SIZE=2][COLOR=#0033ff]import[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] mx.utils.ObjectProxy;
[/SIZE][SIZE=2][COLOR=#0033ff][SIZE=2][COLOR=#0033ff]import[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] mx.rpc.events.ResultEvent;
[[/SIZE][SIZE=2][COLOR=#0033ff][SIZE=2][COLOR=#0033ff]Bindable[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]]

[/SIZE][SIZE=2][COLOR=#0033ff][SIZE=2][COLOR=#0033ff]private[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#6699cc][SIZE=2][COLOR=#6699cc]var[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] userManualObj:ObjectProxy;
[/SIZE][SIZE=2][COLOR=#0033ff][SIZE=2][COLOR=#0033ff]private[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#339966][SIZE=2][COLOR=#339966]function[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] loadModelData(event:ResultEvent):[/SIZE][SIZE=2][COLOR=#0033ff][SIZE=2][COLOR=#0033ff]void[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]{
userManualObj=event.result.UserManual;
}
[/SIZE]
[SIZE=2][COLOR=#0033ff][SIZE=2][COLOR=#0033ff]private
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#339966][SIZE=2][COLOR=#339966]function[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] readXMLContent():[/SIZE]**[SIZE=2][COLOR=#0033ff][SIZE=2][COLOR=#0033ff]void[/LEFT]
**[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]{

[/SIZE][SIZE=2][COLOR=#6699cc][SIZE=2][COLOR=#6699cc]var[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] reportDir:File = File.userDirectory.resolvePath([/SIZE][SIZE=2][COLOR=#990000][SIZE=2][COLOR=#990000]“myassets”[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
[/SIZE][SIZE=2][COLOR=#6699cc][SIZE=2][COLOR=#6699cc]var[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] xmlFile:File;
[/SIZE][SIZE=2][COLOR=#6699cc][SIZE=2][COLOR=#6699cc]var[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] fileStream:FileStream = [/SIZE][SIZE=2][COLOR=#0033ff][SIZE=2][COLOR=#0033ff]new[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] FileStream();
xmlFile = reportDir.resolvePath([/SIZE][SIZE=2][COLOR=#990000][SIZE=2][COLOR=#990000]“example.xml”[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
[/SIZE][SIZE=2][COLOR=#0033ff][SIZE=2][COLOR=#0033ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](xmlFile.exists && xmlFile.size > 0)[/SIZE]*[SIZE=2][COLOR=#009900][SIZE=2][COLOR=#009900]// Checking if the UserGuide.xml file already exists and the file is not empty[/LEFT]
*[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]{
[/SIZE][SIZE=2][COLOR=#6699cc][SIZE=2][COLOR=#6699cc]var[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] stream:FileStream = [/SIZE][SIZE=2][COLOR=#0033ff][SIZE=2][COLOR=#0033ff]new[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] FileStream();
[/SIZE][SIZE=2][COLOR=#6699cc][SIZE=2][COLOR=#6699cc]var[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] xml:XML = [/SIZE][SIZE=2][COLOR=#0033ff][SIZE=2][COLOR=#0033ff]new[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] XML();
stream.open(xmlFile, FileMode.READ);
xml = XML(stream.readUTFBytes(stream.bytesAvailable));
[/SIZE][SIZE=2][COLOR=#6699cc][SIZE=2][COLOR=#6699cc]var[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] strXml:String = xml.toXMLString();
Alert.show(strXml);
[/SIZE][SIZE=2][COLOR=#cc6666][SIZE=2][COLOR=#cc6666]trace[/COLOR][/SIZE][/COLOR][/SIZE]SIZE=2;
stream.close();
}
}

]]>[/LEFT]
[/SIZE][SIZE=2][COLOR=#006633][SIZE=2][COLOR=#006633]</mx:Script>[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#006633][SIZE=2][COLOR=#006633][/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#006633][SIZE=2][COLOR=#006633][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]<mx:SWFLoader[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] height="[/SIZE][SIZE=2][COLOR=#990000][SIZE=2][COLOR=#990000]93[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]" width="[/SIZE][SIZE=2][COLOR=#990000][SIZE=2][COLOR=#990000]708[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]" id="[/SIZE][SIZE=2][COLOR=#990000][SIZE=2][COLOR=#990000]mc_container_0[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]" [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]/>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]<mx:SWFLoader[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] height="[/SIZE][SIZE=2][COLOR=#990000][SIZE=2][COLOR=#990000]393[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]" width="[/SIZE][SIZE=2][COLOR=#990000][SIZE=2][COLOR=#990000]708[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]" id="[/SIZE][SIZE=2][COLOR=#990000][SIZE=2][COLOR=#990000]mc_container_1[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]" [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]/>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]<mx:SWFLoader[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] height="[/SIZE][SIZE=2][COLOR=#990000][SIZE=2][COLOR=#990000]293[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]" width="[/SIZE][SIZE=2][COLOR=#990000][SIZE=2][COLOR=#990000]708[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]" id="[/SIZE][SIZE=2][COLOR=#990000][SIZE=2][COLOR=#990000]mc_container_2[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]" [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]/>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]
[/LEFT]
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]</mx:WindowedApplication>
[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE]

Somehow I need to get the XML data for the file location into each of the SWF loaders, but I simply don’t know how to code it? It’s probably very easy for an expert out there.

Note: I only want to end up with an Air App which will be running locally on my machine.

The idea is, when the XML file changes with new image data, the Air App will display that new image. The image will be added to the “myassets” folder too.

If anyone out can point me in the right direction, it would certainly be appreciated.

Many thanks.

Tim

[/SIZE]