PDA

View Full Version : How to load settings via a XML file in Flex


TheDNA
05-20-2008, 12:56 PM
I am trying this a long time now.
I want to make variable settings for a fileupload.
Via a XML file i want to define the label texts for the buttons.

But how can i do this?
I have searched and tried a long time. All the tutorials i have read are about arraylists and load xml in a datagrid etc.
But how can i do it just simpel and read out 1 line of XML and set this to a label?

my sample xml:
<settings>
<button1>Button1</button1>
</settings>

box86rowh
05-20-2008, 02:32 PM
use an http service connected to your xml, name it dataFinder, then on your app creationcomplete, call dataFinder.send(), then in your code, on your fileUpload set label="{dataFinder.lastResult.button1}"

TheDNA
05-20-2008, 02:48 PM
Thanks for the reply.

I have now this:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="initApp();dataFinder.send(); " alpha="1" themeColor="haloGreen" backgroundGradientAlphas="[0.9, 0.96]" backgroundGradientColors="[#000000, #70828f]">

<mx:Script source="FlexFileUpload_cb.as"/>
<mx:HTTPService
id="dataFinder"
url="FlexFileUpload.xml"
resultFormat="e4x"
/>

<mx:Panel width="652" height="330" layout="absolute" title="File Upload Control">

<mx:DataGrid id="filesDG" left="0" right="0" bottom="30" top="5"/>
<mx:ProgressBar id="progressbar" labelPlacement="center" trackHeight="15" left="0" right="0" bottom="5" height="20"/>

<mx:ControlBar>

<mx:Spacer width="100%"/>
<mx:HBox>
<mx:Button id="browseButton" label="{dataFinder.lastResult.browseButton}"/>
<mx:Button id="uploadButton" label="{dataFinder.lastResult.uploadButton}"/>
<mx:Button id="delButton" label="{dataFinder.lastResult.delButton}"/>
<mx:Button id="clearButton" label="{dataFinder.lastResult.clearButton}"/>
</mx:HBox>

</mx:ControlBar>

</mx:Panel>

</mx:Application>

with XML:
<?xml version="1.0" encoding="utf-8"?>
<FlexFileUpload>
<browseButton>Selecteer bestand</browseButton>
<uploadButton>Verstuur</uploadButton>
<delButton>Verwijdere</delButton>
<clearButton>Reset</clearButton>
</FlexFileUpload>


but i get the error:
[RPC Fault faultString="HTTP request error" faultCode="Server.Error.Request" faultDetail="Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: FlexFileUpload.xml"]. URL: FlexFileUpload.xml"]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::faultHandler()
at mx.rpc::Responder/fault()
at mx.rpc::AsyncRequest/fault()
at ::DirectHTTPMessageResponder/errorHandler()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunctio n()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/flash.net:URLLoader::redirectEvent()

box86rowh
05-20-2008, 02:55 PM
it is not finding your xml file, is it in the same dir as the application?

TheDNA
05-20-2008, 02:56 PM
you will laugh when i tell you what was wrong :D

had a wrong filename :)

box86rowh
05-20-2008, 02:57 PM
That sort of thing happens to me all the time, I usually find it after about 2 hours of deep troubleshooting..lol

TheDNA
05-20-2008, 03:11 PM
if i want to make it multiple languages?

and i want to make the HTTPService URL dynamic via FlashVars?
Is this possible?

Because i didnt had it work.

box86rowh
05-20-2008, 03:19 PM
yup, i do this all the time, just set the url of the http service before you send for the data

TheDNA
05-20-2008, 03:25 PM
hhmm...
am i doing something wrong then?

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="initApp();">

<mx:Script source="FlexFileUpload_cb.as"/>
<mx:HTTPService
id="dataFinder"
url="{xmlFile}"
resultFormat="e4x"
/>


[Bindable]
public var xmlFile:String = Application.application.parameters.xmlFile;
public function initApp():void{
datafinder.Send()
}



I set it in the initApp befor the Send.
But the URL isnt set when i start the app.

box86rowh
05-21-2008, 10:22 PM
set the value of the xmlFile within the initApp function before you send.
That should do it