Load XML from applicationStorageDirectory

Hi all,
I want my app to check the applicationStorageDirectory for an xml file and add an empty one if it is not there. Once this is done I want to load that xml file and work with in the app.
I am trying to use the following method:
private function getLocalQuizDirectoryXML():void
                    var localQuizDir:File = File.applicationStorageDirectory.resolvePath("quizDir.xml");
                    if(!localQuizDir.exists)
                         var fileStream:FileStream = new FileStream();
                         fileStream.open(localQuizDir, FileMode.WRITE);
                         fileStream.writeUTFBytes('<?xml version="1.0" encoding="UTF-8"?><directory></directory>');
                         fileStream.close();
                    var s:FileStream = new FileStream();
                    s.open(localQuizDir, FileMode.READ);
                    localXML = new XML(s.readUTFBytes(s.bytesAvailable));
                    trace(localXML);
The first chunk works and the file is created if it does not exist and the xml is good. In the second chunk, if I trace s.readUTFBytes(s.bytesAvailable) I get the string I wrote in before but when I try to turn that to xml (as in the example) I get nothing. I have also tried using a Loader with the nativePath property in the URLRequest but that just throws an IOError.
Does anyone know how I can load XML from applicationStorageDirectory in to my app so that it is an XML Object rather than a String?
Thankyou kindly

Doh!
I was being incredibly stupid
My method works fine but the XML I am writing is empty so of course it traces nothing!
I put some childNodes in and it works fine. I apologise for wasting wasting valuable internet space with my retarded ramblings I was looking at this for so long I couldn't see it anymore and it took me writing it out here to realise my mistake.
Cheers

Similar Messages

  • Failed to load XML from the package file "" due to error 0xC00CE556 "Invalid at the top level of the document.Line.

    Using Installation wizard to deploy SSIS packages from DEV server to QA server package store cause this error;
    Failed to load XML from the package file "" due to error 0xC00CE556 "Invalid at the top level of the document. Line 773, Column 93". This happens when loading a package and the file cannot be opened or loaded correctly into XML document.  This can be the
    result of either providing an incorrect file name to the LoadPackage method or the XML file specified having an incorrect format.  Please who have the idea of how this issue can be resolved?BI Developer

    Hi ,
       for this Error one and only one solution 
    go to view Code, line number and Column number shown in error message,
    and Remove code from there till last and save it,  it happens when we are moving Package from one server to another server. and VS adds some lines of code at the bottom of package
    something like this 
    andles="1" allownudging="1" isannotation="0" dontautolayout="0" groupcollapsed="0" tabstop="1" visible="1" snaptogrid="0"&gt;
        &lt;control&gt;
          &lt;ddsxmlobjectstreaminitwrapper binary="00080000921400008c040000" /&gt;
        &lt;/control&gt;
        &lt;layoutobject&gt;
          &lt;ddsxmlobj&gt;
            &lt;property name="LogicalObject" value="{BBFB0E
    Remove this code and save package it will work.  
    hope this will help to Developers who are searching for same ......... :) 

  • Loading XML from a server

    Hi,
    I have registered as an Iphone developer at apple website, and was able to package iphone apps successfuly.
    My first experiment was to read a value from an XML file that resides at http://www.mediaplus.com.jo/iphone.xml
    When I test the SWF on my PC it works normally but when I package it and test on my iphone I receive nothing!!
    I am sure it is something about securinty, any help would be highly appreciated!
    Here is the (simple) code I am using
    import flash.events.MouseEvent;
    var all_content:XML;
         function loadXml(xmlPath:String)
                var xml_loader:URLLoader = new URLLoader();
                xml_loader.load( new URLRequest( xmlPath) );
                            xml_loader.addEventListener(Event.COMPLETE, onXmlLoad);
         function onXmlLoad(e:Event):void
            all_content = new XML(e.target.data);
            text_field.text = String(all_content.item);
    btn.addEventListener(MouseEvent.CLICK, retrieve);
    function retrieve (evt:MouseEvent) :void
        loadXml("http://www.mediaplus.com.jo/iphone.xml")

    I've successfully done w/o problems as well.
    Here is what I've used for tests...
    private function loadGallery( feed:String ):void
    var request:URLRequest = new URLRequest( "http://www.site.com/file.xml" );
    var loader:URLLoader = new URLLoader();
    loader.addEventListener( Event.COMPLETE, parseSetup );
    loader.addEventListener( IOErrorEvent.IO_ERROR, xmlError );
    loader.load( request );
    private function parseSetup( event:Event ):void
    var xml:XML = new XML( event.target.data );
    trace( xml );
    private function xmlError( event:IOErrorEvent ):void
    trace("Error loading xml file: " + event);}

  • Loading XML from different server

    Hi, I'm trying to load XML data into flash from a distant
    server. The movie loads the data fine when I run it in my local
    computer, but when I upload it to the web server nothing loads. I'm
    guessing this has to do with cross domain security settings. So I
    added Security.AllowDomain( ); and still not working. Any help
    would be greatly appreciated.
    Thanks!

    you need a cross-domain security file. check the security
    class'es loadPolicyFile() method for help.

  • Import/Load XML from Web Service or URL?

    Hi,
    Like many, I'm new to LCD 8.2.  I have a form with subforms and repeating rows currently bound via a schema, but that can change if need be.  I'm able to import/export file-based XML and that process works well.
    However I'd rather not subject my end-users to browsing for an XML file, and loading it, and I'd like to provide something more elegant. In short, I'd like to import XML from either a web service (returning a single value being the XML document) or by loading the XML directly from a URL by a single button click.
    Is this possible?
    Much appreciated,
    Dave

    http://blogs.adobe.com/stevex/2007/06/http_post_update.html
    http://forms.stefcameron.com/2007/05/21/connecting-to-a-web-service/
    http://www.flexlive.net/?p=70

  • Cannot load image from applicationStorageDirectory

    Hi!
    At program startup I load binary data of images from a remote server and save them locally in my applicationStorageDirectory:
    imageFile = new File(File.applicationStorageDirectory.nativePath);
    imageFile = imageFile.resolvePath("images/" + obj.id + extension);
    var filestream:FileStream = new FileStream();
    filestream.open(imageFile, FileMode.WRITE);
    filestream.writeBytes(loader.data);
    filestream.close();
    later, when I need the image for display reasons, I try to load them from my applicationStorageDirectory:
    file = new File(File.applicationStorageDirectory.nativePath);
    file = file.resolvePath("images/" + obj.id + extension);
    image.load(new URLRequest(file.nativePath));
    I made an output with both urls and they are identical. Nonetheless the image fails to load with error #2035.
    In the desktop version of this application I store images in and load them from the applicationDirectory. This works fine!
    Can anybody help?
    Judith

    I found the solution myself. If I want to load a file from the applicationStorageDirectory I must not reference it with file.nativePath but file.url !
    judith

  • Error 2032 loading xml from swf

    Hello everyone.
    I have a php site (based on Joomla! CMS). In one php page, there is a <object> element wich loads the Adobe Flex 1.5 swf file that I have developed (Slideshow.swf). This swf file is a slideshow that loads a xml file using a httpservice. The xml file contains the urls to the images to be shown. The error occurs when thw swf file tries to load the xml file, but not always.
    - SITUATION 1: Visiting http://localhost/Slideshow.html or http://localhost/Slideshow.swf
      The html and the swf are the files generated by Adobe Flex builder.
      Navigators: IE 8, Mozila Firefox 3.5.5
       --> Yes, it works!!
    - SITUATION 2: Visiting http://mydomaing.com/folder1/folder2/Slideshow.html or http://mydomaing.com/folder1/folder2/Slideshow.swf
      The html and the swf are the files generated by Adobe Flex builder.
      Navigators:
         IE 8 --> Yes, it works!!
         Mozila Firefox 3.5.5   --> I don't get Error 2032, but the images can't be found. This is another problem...
    - SITUATION 3: Visiting http://mydomain.com
      Navigators: IE 8, Mozila Firefox 3.5.5
      --> No, it doesnt' work!! I get Error 2032!!
      The whole page loads. The swf loads, but when the swf tries to load the xml file, the fault event is throwed. Then I use an Alert.show. I'll give you as much information as I can:
    ERROR MESSAGE (FOR SITUATION 3)
    Message: faultCode:Server.Error.Request faultString:'HTTP request error' faultDetail:'Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032"]. URL: ./slideshowGallery.xml'
    Name: Error
    Root cause: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032"]
    Error ID: 0
    Fault code: Server.Error.Request
    Fault detail: Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032"]. URL: ./slideshowGallery.xml
    Fault string: HTTP request error
    FLEX CODE
    <mx:Application 
    xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init();"
    The init method:
    private  
    function init():void{ 
    httpService.send();
    The httpservice element:
    <mx:HTTPServiceid="httpService"url="
    ./slideshowGallery.xml"resultFormat="
    e4x"fault="httpService_fault(event);"
    result="httpService_result(event)"
    />
    I think the handlers don't care. In SITUATION 3, the send() invocation always triggers the fault handler.
    The xml file is in the same folder as the swf file (I use ./slideshowGallery.xml for the url field of the httpservice element).
    This is the html code generated by the php page of my site:
    <div id="ol-flashheader">
    <object type="application/x-shockwave-flash" data="/templates/mx_joofree2/images/header.swf" width="700" height="240">
    <param name="wmode" value="transparent" />
    <param name="movie" value="/templates/mx_joofree2/images/header.swf" />
    </object>
    </div>
    Note: header.swf is my Slideshow.swf renamed.
    Ah, I have also a cross-domain policy file: http://mydomain.com/crossdomain.xml. And the following is curious. The content is:
    <?xml version="1.0"?>
    <!DOCTYPE cross-domain-policy
    SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
    <cross-domain-policy>
      <allow-access-from domain=www.mydomain.com />
      <allow-access-from domain="mydomain.com" />
      <allow-access-from domain="*.mydomain.com" />
    </cross-domain-policy>
    But when i visit http://mydomain.com/crossdomain.xml with IE 8 what i see is:
    <?xml version="1.0"?>
    <!DOCTYPE cross-domain-policy
    SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
    <cross-domain-policy>
      <allow-access-from domain=www.mydomain.com secure="true"/>
      <allow-access-from domain="mydomain.com" secure="true"/>
      <allow-access-from domain="*.mydomain.com" secure="true"/>
    </cross-domain-policy>
    But, when i visit that url with Firefox... correct, It doesn't adds the secure="true" attributes!! jajaja
    Please, I need some advise to solve this problem.
    Thank you very much.
    When I visit the web page (www.mydomain.com) and the swf tries to load

    I haven't found the solution yet, but i can give more info:
    I have modified the crossdomain.xml file to set secure="false". This way, when you view it with Internet Explorer, you can see secure="false" instead of secure="true". But this didn't solve the problem.
    I have read somewhere that avoiding Internet Explorer to cache files, could help. So, I have added the next line to the <header> section of the php page that contains the <object> tag that loads sthe swf file:
    <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
    This didn't solve the problem.
    Regards.

  • A problem with loading xml from external URl in flex

    So I have a server running (localhost) and I wrote an  application to request information from another website and return data  (xml). The application worked fine when I was using the flash builder  and just testing it on my machine (not using the localhost), when I  started using the server with the same exact code, it requested the  crossdomain.xml file to assure that I can request information from that  site, so I added the file and the file is right, the script gets it  (according to firebug), however, it is not getting the xml information  it should get, it just gets stuck with (waiting information from  blah.com) at the bottom.
    Is there a way to solve the problem?
    (I turned my firewall off and it didn't work either)

    Yeah I did test the URL and everything is going fine, the information is not returned to the flex application that's all.
    I am testing with FireBug and it is telling me that the request is in fact sent to the site but I don't think anything (either than the crossdomain function) is returned.
    Thanks for the help, I am really not sure what is going on.

  • Loading XML using a custom class and accessing it from other classes?

    I began with a class for a movie clip rollover function
    FigureRollOver. It works marvellously. Three things happen:
    1) it loads XML from a file "mod1_fig1.xml" and uses another
    class, XMLMember, to retool the scoping of the XML so that I can
    get at it
    2) an onload call inside of XMLMember calls the myOnLoad
    function and transfers the XML into an array.
    3) so long as the array is finished building, rolling over a
    movie clip attaches a new movie clip with the rollover text in it.
    But I don't want all those functions in one because I need it
    to be more dynamic, starting with being able to load any old xml
    file instead of just "mod1_fig1.xml", plus it seems like
    overbuilding to have all of that in one class, so I've separated
    out the loading of the XML and building of the array into its own
    class, FigureXMLLoader. FigureRollOver is then left to just attach
    the rollover with text in it, extracted from the array built by the
    new class.
    Problem is, though the array builds inside FigureXMLLoader, I
    can't figure out how to make it available outside the class. I know
    that I'm constructing things in the wrong order, and that the array
    needs to be somehow built inside the class function to be
    available, but I can't figure out how to do that. A cruddy
    work-around is to put a function call at the end of the building of
    the array, which calls yet ANOTHER function on the main timeline of
    my .swf to put the array I've just built into a new variable. This
    works, but it's messy. It seems like I should be able to have one
    line of script in the .swf that generates an array on the main
    timeline (or just a public array) which I can then access from my
    FigureRollOver class:
    var myRollOvers:Array = new FigureXMLLoader("mod1_fig1.xml");
    Here is FigureXMLLoader (see comments in the code for more
    details) which obviously does not return an array as it is, because
    of all the working around I've had to do. Note the "testing"
    variable, which can be traced from the main timeline of the .swf,
    but I will get "not what I want" because of course the array hasn't
    been built yet, and never will be, inside of the declaration as it
    is. How do I get it in there so I can return an array?
    Thanks!

    Suggest you ask this question in the Actionscript forum as
    this forum is
    more tuned to database integration questions.
    You can create arrays outside a class and pass them into it
    by reference and
    visa versa build arrays inside a class and pass out via
    reference.
    The preferred approach is to place the array in a class and
    not expose it.
    Then add methods to use the array or should we say to use the
    class.
    Lon Hosford
    www.lonhosford.com
    Flash, Actionscript and Flash Media Server examples:
    http://flashexamples.hosfordusa.com
    May many happy bits flow your way!
    "maija_g" <[email protected]> wrote in
    message
    news:ed4i43$9v0$[email protected]..
    > Update: I've now put this on the main timeline of the
    .swf:
    >
    > myRollOversLoaded = false;
    > var myRollOvers:Array;
    > var roll_content = new FigureXMLLoader("mod1_fig1.xml");
    >
    > And inside the "myOnLoad" function in FigureXMLLoader,
    just after the
    > while
    > loop I've put this:
    >
    > _root.myRollOversLoaded = true;
    > _root.myRollOvers = figure_arr;
    >
    > The movie clip rollover won't act until
    myRollOversLoaded is true. It
    > works,
    > but it still seems klugey. Any suggestions for a more
    elegant solution
    > would be
    > appreciated.
    >

  • Flash CC Air iOS: Problems with loading text from an external xml located on a server.

    So I have this code allowing me to load text from an xml located on a server. Everything works fine on the Air for Android. The app even works in the ios emulator, but once I export my app to my ios device with ios 7, I don't see any text. The app is developed with Air sdk 3.9. What could be the reason? Do I need any special permissions like on Android? Does ios even allow to load xml from an external server?
    Any clues?

    It was my bad. I linked to a php file to avoid any connection lags, which was absolutely fine on the android, but didn't seem to work on the ios 7. So all I did is change the php extension to xml and it worked without any problems.

  • Unable to load any XML from JAR - Please help!!

    Hi All,
    I am a student in the final days of my degree. I have been working on my final project for some time now, an applet which converts input text to a signal plot for line encoding schemes - AMI, NRZ etc. It is pretty much finished, but one small bug threatens to scuttle the entire project! I have been searching the web all day long for answers with little success, and as the castor forum still appears to be down I am posting here. Any suggestions or advice would be greatly appreciated.
    The applet uses the castor databinding framework to load various XML data. I am using Eclipse 3.01 for development - when the program is run locally as an applet, everything works fine. When the program is bundled into a JAR file and nested into a clean folder with a html page and the jar file, when the command to read in XML is given, a NullPointerException occurs, indicating that castor was unable to access the XML files.
    Below is one of the methods used to make castor load XML data:
         public CodeSet loadCodeXML(String _codesetFilename)
              String _mappingURI = "schema/codes/codesets-mapping.xml";
              String _codesetURI = "schema/codes/" + _codesetFilename;
                    // Create a new Castor mapping object
              Mapping mapping = new Mapping();                         
            try                                                                 // Attempt to load in the selected XML character set
                 mapping.loadMapping(_mappingURI);                    // Initialize 'mapping' with the map file
                Unmarshaller unmar = new Unmarshaller(mapping); // Create a new XML Unmarshaller that uses 'mapping'
                // The line below creates a new CharSet object called _codeset and populates it with the XML data
                CodeSet _codeset = (CodeSet)unmar.unmarshal(new InputSource(new FileReader(_codesetURI)));
                // The character set was successfully loaded, so pass new CharSet object back to caller and end
                return _codeset;
            } catch (Exception e) {
                 // If an error occurs while extracting the XML data, this block will execute:
                JOptionPane.showMessageDialog(null, e);               // Display a message dialog containing the exception error
                return null;                                             // Do not return a CharSet object to caller
         }It would seem to me the problem lies within
              String _mappingURI = "schema/codes/codesets-mapping.xml";
              String _codesetURI = "schema/codes/" + _codesetFilename;I have read that files inside a JAR can be accessed in this way ( http://archive.codehaus.org/castor/user/msg00025.html ) but it won't appear to work.
    If these are set to a full system path (outside any JAR) i.e. "/home/me/proj/schema/codes/codesets-mapping.xml", the application operates fine. Clearly this is no good however, as the XML data must reside within the JAR package. I have tried many permutations such as "jar://schema/..." , "/schema/..", "schema/..", with no success. I have read of using InputStream and getResource methods to access files within the jar but have had no success. I have checked the schema dir is being put into the JAR archive.
    Could anyone suggest an appropriate way of loading XML files from within a JAR file in this context?
    Thanks in advance for any replies.

    Hi, me again..
    Re: mr_doghead - the filename of the file is passed from the calling function
    public CodeSet loadCodeXML(String _codesetFilename)eg loadCodeXML(ami.xml) will return a CodeSet object containing the ami xml data
    Anyway, I've manged to fix it up. The problem actually lies within castor, not my code at all. This is a known bug in castor that the dev's deemed 'not important' to fix, but I have to say the work around is EXTREMLY poorly documented online. Hence, this post is just to say how to fix it up if ne1 else is having trouble...
    To load mappings, use:
    mapping.loadMapping(getClass().getResource(_mappingURI).toString());where _mappingURI is a string such as "/xml/mapfile.xml"
    However, the unmarshalling method takes in a file object, so getResourceAsStream must be used:
    CharSet _charset = (CharSet)unmar.unmarshal(new InputSource(getClass().getResourceAsStream(_charsetURI)));Where CharSet is your custom object you are marshalling into, and _charsetURI is a relative path to your xml file.
    Ugly as hell? Very.
    Does it work? Perfectly.
    take it ez guys, time for me to go hand this sht in! ;D

  • Issue to load data from database to XML file. error: ODI-40768

    Hi,
    While I am trying to load data from database to XML following error is appearing.
    ODI-1228: Task TEST_XML_DATA (Integration) fails on the target XML connection MyLOCALXSD.
    Caused By: java.sql.SQLException: ODI-40768: Could not save the file <default>:C:\DATA_FILE\www.xml because a class java.io.IOException occurred and said: The filename, directory name, or volume label syntax is incorrect
         at com.sunopsis.jdbc.driver.xml.SnpsXmlFile.writeToFile(SnpsXmlFile.java:751)
         at com.sunopsis.jdbc.driver.xml.SnpsXmlConnection.internalExecute(SnpsXmlConnection.java:769)
         at com.sunopsis.jdbc.driver.xml.SnpsXmlPreparedStatement.execute(SnpsXmlPreparedStatement.java:46)
         at oracle.odi.runtime.agent.execution.sql.SQLCommand.execute(SQLCommand.java:166)
         at oracle.odi.runtime.agent.execution.sql.SQLExecutor.execute(SQLExecutor.java:102)
         at oracle.odi.runtime.agent.execution.sql.SQLExecutor.execute(SQLExecutor.java:1)
         at oracle.odi.runtime.agent.execution.TaskExecutionHandler.handleTask(TaskExecutionHandler.java:50)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.processTask(SnpSessTaskSql.java:2906)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java:2609)
         at com.sunopsis.dwg.dbobj.SnpSessStep.treatAttachedTasks(SnpSessStep.java:540)
         at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java:453)
         at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:1740)
         at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$2.doAction(StartSessRequestProcessor.java:338)
         at oracle.odi.core.persistence.dwgobject.DwgObjectTemplate.execute(DwgObjectTemplate.java:214)
         at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.doProcessStartSessTask(StartSessRequestProcessor.java:272)
         at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.access$0(StartSessRequestProcessor.java:263)
         at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$StartSessTask.doExecute(StartSessRequestProcessor.java:822)
         at oracle.odi.runtime.agent.processor.task.AgentTask.execute(AgentTask.java:123)
         at oracle.odi.runtime.agent.support.DefaultAgentTaskExecutor$2.run(DefaultAgentTaskExecutor.java:83)
         at java.lang.Thread.run(Thread.java:662)
    jdbc url: jdbc:snps:xml?d=C:\test_xsd.xsd&s=TESTSQL&re=employeesX&ro=true
    physical schema: TESTSQL
    Knowledge modules are:
    LKM: LKM SQL to SQL
    IKM: IKM XML Control Append
    CKM: CKM SQL
    Parameters set are:
    CREATE_XML_FILE: true
    XML_PATH:<default>:C:\DATA_FILE\www.xml
    I have tried to change the directory path but error is still there.
    Could some one please help me to resolve the issue?
    Regards,
    user1672911

    Hi,
    The trouble in "<default>:"  - if you set XML_PATH as C:\DATA_FILE\www.xml instead  <default>:C:\DATA_FILE\www.xml- it will work correctly.
    Greetings,
    Eugene

  • Load XML file from different location?

    Hi All,
    I've been going through an exercise by Karl Matthews to load XML data into an AIR App:
    http://www.adobe.com/devnet/air/flex/articles/xml_viewer_on_air.html
    but I would like to change where the XML file used in the project is retrieved from.
    Currently the XML file is loaded from here:
    <!-- Set up the HTTP service from where we get the source XML data -->
    <mx:HTTPService id="srcData" url="
    assets/UserGuide.xml" result="loadModelData(event)"
    />
    but I would like to load the XML file from one of these locations instead:
    File.userDirectory:
    File.documentsDirectory:
    Can someone please show me how I should change the above code to accomplish this, as my efforts to date have not been successful :-(
    I am using Flex Builder 3 and Air 1.5.
    Thanks heaps!
    Tim

    Hi Bhasker,
    Thank you for replying.
    I am not very good at all this coding, but I am assuming I should now be doing entering the following:
    =======================
    <?xml version="1.0" encoding="utf-8"?>
    <mx:WindowedApplication 
    xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"width="
    800" height="660"xmlns:comp="
    *" xmlns:fmtComp="fmtComps.*"creationComplete="srcData.send()"
    paddingLeft="
    0" paddingRight="0" paddingTop="0" paddingBottom="0">
    <mx:Script>
    <![CDATA[
    import mx.utils.ObjectProxy; 
    import mx.rpc.events.ResultEvent; 
    Bindable] 
    private var userManualObj:ObjectProxy; 
    private function loadModelData(event:ResultEvent):void
    userManualObj=event.result.UserManual;
    private function readXMLContent(xmlFile:File,objContentView:Object):Array{
    var reportDir:File = File.userDirectory.resolvePath("assets"); 
    var xmlFile:File; 
    var fileStream:FileStream = new FileStream(); xmlFile = reportDir.resolvePath(
    "UserGuide.xml"); 
    if(xmlFile.exists && xmlFile.size > 0)// Checking if the impressions.xml file already exists and the file is not empty
    var stream:FileStream = new FileStream(); 
    var xml:XML = new XML();stream.open(xmlFile, FileMode.READ);
    xml = XML(stream.readUTFBytes(stream.bytesAvailable));
    stream.close();
    ]]>
    </mx:Script>
    <!-- Set up the HTTP service from where we get the source XML data<mx:HTTPService id="srcData"
    url="assets/UserGuide.xml"
    result="loadModelData(event)"/> -->
    <mx:VBox width="100%" horizontalAlign="left" height="100%" paddingBottom="
    0" paddingLeft="0" paddingRight="0" paddingTop="0">
    <mx:TabNavigator width="100%" height="100%"paddingBottom="
    0" paddingLeft="0" paddingRight="0" paddingTop="0">
    <mx:Repeater id="modelsRep" dataProvider="{userManualObj.Product.Model}">
    <mx:VBox label="{modelsRep.currentItem.Name}" width="100%" height="100%">
    <comp:ModelDesc model="{modelsRep.currentItem}"/>  
    </mx:VBox>
    </mx:Repeater>
    <mx:VBox label="Troubleshooting" width="100%" height="100%"paddingBottom="
    0" paddingLeft="0" paddingRight="0" paddingTop="0">
    <comp:Troubleshooting issues="{userManualObj.Product.Troubleshooting.Issue}" />
    </mx:VBox>
    </mx:TabNavigator>
    </mx:VBox></mx:WindowedApplication>
    =======================
    and create and "assets" folder in my user directory placing the XML file in there?
    However when I do all that, I get this error when I try to compile:
      Encountered errors or warnings while building project main.mxml.
        main.mxml: Function does not return a value.
    Any thoughts?
    Many thanks,
    Tim

  • Load XML file from addon domain without cross-domain Policy file

    Hello.
    Assuming that there are two addon domains on the same server: /public_html/domain1.com       and      /public_html/domain2.com
    I try to load XML file from domain2.com into domain1.com without using cross-domain policy file (since it doesn’t work on xml files in my case).
    So the idea is to use php file in order to load XML and read it back to flash.
    I’ve found an interesting scripts that seems to do the job but unfortunately I can't get it to work. In my opinion there is somewhere problem with AS3 part. Please take a look.
    Here are the AS3/PHP scripts:
    AS3 (.swf in www.domain1.com):
    // location of the xml that you would like to load, full http address
    var xmlLoc:String = "http://www.domain2.com/MyFile.xml";
    // location of the php xml grabber file, in relation to the .swf
    var phpLoc:String = "loadXML.php";
    var xml:XML;
    var loader:URLLoader = new URLLoader();
    var request:URLRequest = new URLRequest(phpLoc+"?location="+escape(xmlLoc) );
    loader.addEventListener(Event.COMPLETE, onXMLLoaded);
    loader.addEventListener(IOErrorEvent.IO_ERROR, onIOErrorHandler);
    loader.load(request);
    function onIOErrorHandler(e:IOErrorEvent):void {
        trace("There was an error with the xml file "+e);
    function onXMLLoaded(e:Event):void {
        trace("the rss feed has been loaded");
        xml = new XML(loader.data);
        // set to string, since it is passed back from php as an object
        xml = XML(xml.toString());
        xml_txt.text = xml;
    PHP (loadXML.php in www.domain1.com):
    <?php
    header("Content-type: text/xml");
    $location = "";
    if(isset($_GET["location"])) {
        $location = $_GET["location"];
        $location = urldecode($location);
    $xml_string = getData($location);
    // pass the url encoded vars back to Flash
    echo $xml_string;
    //cURLs a URL and returns it
    function getData($query) {
        // create curl resource
        $ch = curl_init();
        // cURL url
        curl_setopt($ch, CURLOPT_URL, $query);
        //Set some necessary params for using CURL
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
       //Execute the curl function, and decode the returned JSON data
        $result = curl_exec($ch);
        return $result;
        // close curl resource to free up system resources
        curl_close($ch);
    ?>

    I think you might be right about permissions/settings on the server for php. Unfortunately I'm not allowed to adjust them.
    So I wrote my own script - this time I used file path instead of http address of the XML file.  It works fine in my case.
    Here it is:
    XML file on domain2.com:
    <?xml version="1.0" encoding="UTF-8"?>
    <gallery>
        <image imagePath="galleries/gallery_1/images/1.jpg" thumbPath="galleries/gallery_1/thumbs/1.jpg" file_name= "1"> </image>
        <image imagePath="galleries/gallery_1/images/2.jpg" thumbPath="galleries/gallery_1/thumbs/2.jpg" file_name= "2"> </image>
        <image imagePath="galleries/gallery_1/images/3.jpg" thumbPath="galleries/gallery_1/thumbs/3.jpg" file_name= "3"> </image>
    </gallery>
    swf  on domain1.com:
    var imagesXML:XML;
    var variables:URLVariables = new URLVariables();
    var varURL:URLRequest = new URLRequest("MyPHPfile.php");
    varURL.method = URLRequestMethod.POST;
    varURL.data = variables;
    var MyLoader:URLLoader = new URLLoader;
    MyLoader.dataFormat =URLLoaderDataFormat.VARIABLES;
    MyLoader.addEventListener(Event.COMPLETE, XMLDone);
    MyLoader.load(varURL);
    function XMLDone(event:Event):void {
        var imported_XML:Object = event.target.data.imported_XML;
        imagesXML = new XML(imported_XML);
       MyTextfield_1.text = imagesXML;
       MyTextfield_2.text = imagesXML.image[0].attribute("thumbPath");  // sample reference to attribute "thumbPath" of the first element
    php file on domain1.com:
    <?php
    $xml_file = simplexml_load_file('../../domain2.com/galleries/gallery_1/MyXMLfile.xml');  // directory to XML file on the same server
    $imported_XML = $xml_file->asXML();
    print "imported_XML=" . $imported_XML;
    ?>
    Regards
    PS: for those who read the above discussion: the first and the second script work but you must test which one is better in your situation. The first script will also work between two domains on different servers. No cross domain policy file needed.

  • Can I load xml file from SWC without using @embed

    I'm developing a mobile application in which I need to load xml files from File.applicationDirectory. This works great if the xml files are part of the main application swf. But I would like to move these xml files into a SWC so they could be shared across multiple applications.
    Using FlashBuilder 4.5, when a SWC is built, I can specify files to embed in the library that are not assets (Assets Tab of Flex Library Build Path). For various design reasons, I do NOT want to embed the xml files via @embed.
    When the swc is built and I open it up using a zip utility, I see the xml files in there just fine. So they are being bundled with the SWC. But how can I load these files in my main application that does not involve using @embed? When the main application is built, the swc setting for link type is "merged into code".
    I wouldn't expect the application to automatically pull out the xml files from the swc and place them in the File.applicationDirectory on the mobile device. I've tried loading from there just in case but file.exists is false (as expected).
    I've searched the web (and continue to do so) and all the answers seem to be to use @embed. Is there another way?
    Randy

    It's actually a lot easier than you think.
    Just reference the file like any'ol URL using a path relative to the SWC's src directory.
    So if you include the file "assets/xml/some.xml", just use that same string like you would any remote resource.
    For example:
    var loader:URLLoader = new URLLoader( new URLRequest("assets/xml/some.xml"));
    I believe it would also work like this "/assets/xml/some.xml", but I prefer relative paths so the link doesnt break if moved out of the SWC...

Maybe you are looking for