4 Replies Latest reply on Aug 15, 2011 4:56 PM by Joe ... Ward

    Problem: XML can not write currectly =(

    Jens Eckervogt Level 1

      Hello

       

      i am developing with Adobe Air 3.0 Beta and i will create an application like Texture and Graphic Maker like alternative PhotoShop.

       

      I have problem with xml:

       

      But i am not finish for completed application. I am sorry for poor english.

       

      I will to knnow about creating and existing folders. there are simple so like MDM Zinc App creates a lot of folders. It has not problem.

      Now i will know with Adobe Air  2.7.1 - 3.0 Beta x.

       

      But i have been tried with looking directory:

      For Windows 7:

      C:\Users\<Username>\

      I have been written this code:

      private var smFolder:String = "SnakeMedia Inc//";
      private var configureFolder:String = "Configures//";
      private var palletsFolder:String = "Pallets//";
      private var pluginsFolder:String = "Plugins//";
      private var extensionsFolder:String = "Extensions//";
                     
      private var Folder_SM:File = File.userDirectory.resolvePath(smFolder);
      private var Folder_SM_CFG:File = File.userDirectory.resolvePath(smFolder + configureFolder);
      private var Folder_SM_PATS:File = File.userDirectory.resolvePath(smFolder + palletsFolder);
      private var Folder_SM_PLG:File = File.userDirectory.resolvePath(smFolder + pluginsFolder);
      private var Folder_SM_EXT:File = File.userDirectory.resolvePath(smFolder + extensionsFolder);
      
      protected function smTmInit():void
      {
           /*
                Creating and existsing directory from userdirectory/SnakeMedia Inc/
           */
           if(Folder_SM.exists || Folder_SM_CFG.exists || Folder_SM_PATS.exists || Folder_SM_PLG.exists || Folder_SM_EXT.exists){
                Folder_SM.isDirectory;
                Folder_SM_CFG.isDirectory;
                Folder_SM_PATS.isDirectory;
                Folder_SM_PLG.isDirectory;
                Folder_SM_EXT.isDirectory;
           }else{
                Folder_SM.createDirectory();
                Folder_SM_CFG.createDirectory();
                Folder_SM_PATS.createDirectory();
                Folder_SM_PLG.createDirectory();
                Folder_SM_EXT.createDirectory();
           }
      }
      

       

      Result like this directory:

      /SnakeMedia Inc

      ../Configures

      ../Pallets

      ../Plugins

      ../Extensions

       

      It really works sure.

       

      But it has problem with File like config.xml or config.smcf ( I like custom file type for my company name. = SnakeMedia Configured File = *.smcf )

       

      And i have been coded again:

      private var cfgFile:String = "config.smcf";
      
      private var File_SM_CF:File = File.userDirectory.resolvePath(smFolder + configureFolder + cfgFile);
      private var FileStream_SM_CF:FileStream = new FileStream();
                     
      private var XML_CFG_HEADER:String = '<?xml version="1.0" encoding="utf-8"?> \n';
      private var XML_CFG_CONTENT:String = '<!-- SnakeMedia Inc - Configure File -->\n';
      private var XML_CFG:XML = new XML("<smConfig></smConfig>");
      
      // in the Function " smTmInit() "
      
      /*
           Creating and Writing configured Files
      */
      if(File_SM_CF.exists){
           FileStream_SM_CF.open(File_SM_CF, FileMode.READ);
           XML_CFG = XML(FileStream_SM_CF.readUTFBytes(FileStream_SM_CF.bytesAvailable));
           FileStream_SM_CF.close();
      }else{
           WriteCfgFile(XML_CFG.toXMLString());
      }
      
      // Function WriteCfgFile()
      
      protected function WriteCfgFile(XML_CFG_CONTENT:String):void
      {
           FileStream_SM_CF.open(File_SM_CF, FileMode.WRITE);
           XML_CFG_HEADER += XML_CFG_CONTENT;
           XML_CFG_CONTENT += XML_CFG_CONTENT;
           FileStream_SM_CF.writeUTFBytes(XML_CFG_HEADER);
           FileStream_SM_CF.writeUTFBytes(XML_CFG_CONTENT);
           FileStream_SM_CF.close();
      }
      

       

      And i save it than i ruh into Adobe Air Application and Air App will create directory into userDirectory and write a configured file from /SnakeMedia Inc/Configures/config.smcf

       

      And i will verify this file config.smcf and open Notepad / Notepad++ with config.smcf

      Result is very crazy

      It is not possible How do i fix Configured File Structure?

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

       

      I will know when Air App should write like this:

      <?xml version="1.0" encoding="utf-8"?>
      
      <!-- SnakeMedia Inc - Configured File -->
      <smConfig>
           <smSetup>
                <smPref>
                     <Width>600</Width>  <-- Like you know about old example by Adobe AIr 1.5 Preferences with size
                     <Height>460</Height>
                </smPref>
           </smSetup>
           <smApp>
                ...
           </smApp>
      </smConfig>
      

       

      Please make sure! "<--" I mean telling about old time of your example of Adobe Air 1.5 with Preferences with resuzing and saving...

       

      I hope becasue you can reply me and make suggestions for me Thanks! If i know sure....

       

      Do not worry! I am not faker

      I am working with Adobe Air and Flash Builder 4.5.1

       

      Thanks best regards, Mister Eckervogt

        • 1. Re: Problem: XML can not write currectly =(
          Joe ... Ward Level 4

          In your WriteCfgFile(XML_CFG_CONTENT:String):void function, you use a parameter name that is the same as the class variable name containing your XML. Change the parameter name and your function should work better.

           

           

          Sent from my Verizon Wireless 4GLTE smartphone

          • 2. Re: Problem: XML can not write currectly =(
            Jens Eckervogt Level 1

            Thank you! I try again

            • 3. Re: Problem: XML can not write currectly =(
              Jens Eckervogt Level 1

              It always crazy

               

              I am trying it can not work becasue XML has problem? Is it possible bug? or double writing?

               

              Look like this:

               

              import flash.events.*;
                             
                   private var smFolder:String = "SnakeMedia Inc//";
                   private var configureFolder:String = "Configures//";
                   private var palletsFolder:String = "Pallets//";
                   private var pluginsFolder:String = "Plugins//";
                   private var extensionsFolder:String = "Extensions//";
                   private var cfgFile:String = "config.smcf";
                   
                   private var Folder_SM:File = File.userDirectory.resolvePath(smFolder);
                   private var Folder_SM_CFG:File = File.userDirectory.resolvePath(smFolder + configureFolder);
                   private var Folder_SM_PATS:File = File.userDirectory.resolvePath(smFolder + palletsFolder);
                   private var Folder_SM_PLG:File = File.userDirectory.resolvePath(smFolder + pluginsFolder);
                   private var Folder_SM_EXT:File = File.userDirectory.resolvePath(smFolder + extensionsFolder);
                   
                   private var File_SM_CF:File = File.userDirectory.resolvePath(smFolder + configureFolder + cfgFile);
                   private var FileStream_SM_CF:FileStream = new FileStream();
                   
                   private var XML_CFG_HEADER:String = '<?xml version="1.0" encoding="utf-8"?> \n';
                   private var XML_CFG_HEADER_CONTENT:String = '<!-- SnakeMedia Inc - Configured File -->\n';
                   private var XML_CFG_STRUCTUR_START_SMCFG:String = "<smConfig>\n" + File.lineEnding;
                   private var XML_CFG_STRUCTUR_END_SMCFG:String = "</smConfig>\n" + File.lineEnding;
                   private var XML_CFG:XML;
                             
                   protected function smTmInit():void
                   {
                   /*
                        Creating and existsing directory from userdirectory/SnakeMedia Inc/
                   */
                        if(Folder_SM.exists || Folder_SM_CFG.exists || Folder_SM_PATS.exists || Folder_SM_PLG.exists || Folder_SM_EXT.exists){
                        Folder_SM.isDirectory;
                        Folder_SM_CFG.isDirectory;
                        Folder_SM_PATS.isDirectory;
                        Folder_SM_PLG.isDirectory;
                        Folder_SM_EXT.isDirectory;
                   }else{
                        Folder_SM.createDirectory();
                        Folder_SM_CFG.createDirectory();
                        Folder_SM_PATS.createDirectory();
                        Folder_SM_PLG.createDirectory();
                        Folder_SM_EXT.createDirectory();
                   }
                   /*
                        Creating and Writing configured Files
                   */
                   if(File_SM_CF.exists){
                        FileStream_SM_CF.open(File_SM_CF, FileMode.READ);
                        XML_CFG = XML(FileStream_SM_CF.readUTFBytes(FileStream_SM_CF.bytesAvailable));
                        FileStream_SM_CF.close();
                   }else{
                        XML_CFG = XML(XML_CFG_STRUCTUR_START_SMCFG + XML_CFG_STRUCTUR_END_SMCFG);
                        WriteCfgFile(XML_CFG.toXMLString());
                   }
                   /*
                        SnakeMedia Texture Maker Application
                   */
              }
                             
              protected function WriteCfgFile(XML_CFG_CONTENT:String):void
              {
                   FileStream_SM_CF.open(File_SM_CF, FileMode.WRITE);
                   XML_CFG_HEADER += XML_CFG_CONTENT;
                   XML_CFG_HEADER_CONTENT += XML_CFG_CONTENT;
                   XML_CFG_STRUCTUR_START_SMCFG += XML_CFG_CONTENT;
                   XML_CFG_STRUCTUR_END_SMCFG += XML_CFG_CONTENT;
                   FileStream_SM_CF.writeUTFBytes(XML_CFG_HEADER);
                   FileStream_SM_CF.writeUTFBytes(XML_CFG_HEADER_CONTENT);
                   FileStream_SM_CF.writeUTFBytes(XML_CFG_STRUCTUR_START_SMCFG);
                   FileStream_SM_CF.writeUTFBytes(XML_CFG_STRUCTUR_END_SMCFG);
                   FileStream_SM_CF.close();
              }
              

               

               

              Result for config.smcf:

               

              <?xml version="1.0" encoding="utf-8"?> 
              <smConfig/><!-- SnakeMedia Inc - Configured File -->
              <smConfig/><smConfig>
              
              <smConfig/></smConfig>
              
              <smConfig/>
              

               

               

              I am trying with writing config - it will write current

               

              I want to know - how does Adobe Air fix when i see current result like this?

               

              <?xml version="1.0" encoding="utf-8"?> 
              <!-- SnakeMedia Inc - Configured File -->
              <smConfig>
                   ...
              <smConfig>
              

               

               

              I have been tried another function like removing line example private var XML_CFG:XML = XML(Structur_start + Structur_end);

              But it can not work. When i do not want to remove config file than Adobe Air App gets error:

               

               

              TypeError: Error #1088: The markup in the document following the root element must be well-formed.
                   at TextureMaker/smTmInit()[H:\src\zinc\TextureMaker\src\TextureMaker.mxml:56]
                   at TextureMaker/___TextureMaker_WindowedApplication1_applicationComplete()[H:\src\zinc\TextureMaker\src\TextureMaker.mxml:5]
                   at flash.events::EventDispatcher/dispatchEventFunction()
                   at flash.events::EventDispatcher/dispatchEvent()
                   at mx.core::UIComponent/dispatchEvent()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\core\UIComponent.as:13128]
                   at mx.managers::SystemManager/preloader_preloaderDoneHandler()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\SystemManager.as:2682]
                   at flash.events::EventDispatcher/dispatchEventFunction()
                   at flash.events::EventDispatcher/dispatchEvent()
                   at mx.preloaders::Preloader/displayClassCompleteHandler()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\preloaders\Preloader.as:582]
                   at flash.events::EventDispatcher/dispatchEventFunction()
                   at flash.events::EventDispatcher/dispatchEvent()
                   at mx.preloaders::SparkDownloadProgressBar/initCompleteHandler()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\preloaders\SparkDownloadProgressBar.as:1087]
                   at flash.events::EventDispatcher/dispatchEventFunction()
                   at flash.events::EventDispatcher/dispatchEvent()
                   at mx.preloaders::Preloader/dispatchAppEndEvent()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\preloaders\Preloader.as:380]
                   at mx.preloaders::Preloader/appCreationCompleteHandler()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\preloaders\Preloader.as:590]
                   at flash.events::EventDispatcher/dispatchEventFunction()
                   at flash.events::EventDispatcher/dispatchEvent()
                   at mx.core::UIComponent/dispatchEvent()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\core\UIComponent.as:13128]
                   at mx.core::UIComponent/set initialized()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\core\UIComponent.as:1818]
                   at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\LayoutManager.as:842]
                   at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1180]
              

               

               

              Why does it not rewrite again? When config file loads currently?

               

              Thanks for replies

               

              Best regards, Mister Eckervogt

              • 4. Re: Problem: XML can not write currectly =(
                Joe ... Ward Level 4

                I think the app is doing exactly what you are telling it to do.

                 

                Take this function:

                 

                protected function WriteCfgFile(XML_CFG_CONTENT:String):void

                {     

                FileStream_SM_CF.open(File_SM_CF, FileMode.WRITE);     

                XML_CFG_HEADER += XML_CFG_CONTENT;     

                XML_CFG_HEADER_CONTENT += XML_CFG_CONTENT;     

                XML_CFG_STRUCTUR_START_SMCFG += XML_CFG_CONTENT;     

                XML_CFG_STRUCTUR_END_SMCFG += XML_CFG_CONTENT;     

                FileStream_SM_CF.writeUTFBytes(XML_CFG_HEADER);     

                FileStream_SM_CF.writeUTFBytes(XML_CFG_HEADER_CONTENT);      FileStream_SM_CF.writeUTFBytes(XML_CFG_STRUCTUR_START_SMCFG);      FileStream_SM_CF.writeUTFBytes(XML_CFG_STRUCTUR_END_SMCFG);

                 

                 

                You pass in the string, "<smconfig/>" (the result of toXMLString on the document with only a root node)

                Expanding your assignment statements gives:

                XML_CFG_HEADER = "<?xml version="1.0" encoding="utf-8"?>" + "<smconfig/>"

                XML_CFG_HEADER_CONTENT = "<!-- SnakeMedia Inc - Configured File -->" + "<smconfig/>"

                XML_CFG_STRUCTUR_START_SMCFG = "<smconfig>" + "<smconfig/>"

                XML_CFG_STRUCTUR_END_SMCFG = "</smconfig>" + "<smconfig/>"

                 

                And then you print XML_CFG_HEADER + XML_CFG_HEADER_CONTENT + XML_CFG_STRUCTUR_START_SMCFG +XML_CFG_STRUCTUR_END_SMCFG

                 

                Which gives:

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

                <!-- SnakeMedia Inc - Configured File --><smconfig/>

                <smconfig><smconfig/>

                </smconfig><smconfig/>