2 Replies Latest reply on Apr 16, 2010 10:44 PM by David_F57

    creating costum config file

    birgani

      Hello guys,

       

      I am trying to creat an air app in flex 4. I have an XML file and saved it in the same directory as my compiled air file is. ( c:\programfiles\myApp)

      the application should use the xml file to set some of my vars.

      the xml format is like this:

       

      <numberOfImages> 20 </ numberOfImages>

      ...

       

      and in the main mxml file sould use that xml file and show 20 images per page. and the user just change the xml file and it will change the number of images with out having to know any thing about flex or compiling the app one more time.

       

      the problem is that my app is not loading the xml file.

      and the cod looks like this:

       

      var request:URLRequest = new URLRequest("app:/myConfig.xml");

      var loader:URLLoader = new URLLoader();

      loader.addEventListener(Event.COMPLETE, configResultHandler);

      loader.addEventListener(IOErrorEvent.IO_ERROR, onLoadError);

      loader.load(request);

       

      i dont want to give it absolute path like c:\program files\my app. the app will save the xml file in the same directory of the executable file.

      can anybody tell my what I am doing wrong?

       

       

      Many thanks,

        • 1. Re: creating costum config file
          David_F57 Level 5

          hi,

           

          the following works fine

           

          <?xml version="1.0" encoding="utf-8"?>

          <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"

             xmlns:s="library://ns.adobe.com/flex/spark"

             xmlns:mx="library://ns.adobe.com/flex/mx"

             creationComplete="windowedapplication1_creationCompleteHandler(event)">

          <fx:Declarations>

          <!-- Place non-visual elements (e.g., services, value objects) here -->

          </fx:Declarations>

          <fx:Script>

          <![CDATA[

          import mx.events.FlexEvent;

           

           

          protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void

          {

          var loader:URLLoader = new URLLoader(new URLRequest("config.xml"));

          loader.addEventListener(Event.COMPLETE,onComplete);

          }

           

          private function onComplete(event:Event):void

          {

          trace(event.target.data);

          }

           

          ]]>

          </fx:Script>

          </s:WindowedApplication>

          • 2. Re: creating costum config file
            David_F57 Level 5

            Hi,

             

            On another note have you considered using sharedobjects for configuration, this is a great way of having 'local' configuration settings for both AIR and web based Flex applications.

             

            David.