Language: ChineseGermanSpanishFrenchDutchItalianRussian
123 Flash Chat Forums

Go Back   TOPCMM Community > SWFKit > SWFKit Support

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-24-2005, 06:01 PM
Junior Member
 
Join Date: Jun 2003
Posts: 29
Default Problem reading an INI file

I'm having problems reading an ini file:

Code:
function getAppIniSettings(){
var vFile= "C:\\Projects\\player.ini";
trace("File.exists(vFile) : " + vFile + " exists? " + File.exists(vFile) );
var iniFile = new Ini(vFile);
trace("iniFile: " + iniFile);
                trace("getSection: " + iniFile.getSection("Resolution"));
trace("getSectionNames: " + iniFile.getSectionNames());
}
getAppIniSettings();
The following output is traced:

FSCommand("FFish_Run", "Initialize")
File.exists(vFile) : C:\Projects\player.ini exists? true
iniFile: [object INI]
getSection:
getSectionNames:

The ini file contains:
Code:
[Resolution]
width=1024
height=768
I can not access the section or key values.

Any ideas?

Thanks,

Steve
Reply With Quote
  #2 (permalink)  
Old 11-24-2005, 09:23 PM
Junior Member
 
Join Date: Apr 2005
Posts: 8
Default Re:Problem reading an INI file

try this
Code:
function getAppIniSettings(){
   var vFile= "C:\\Projects\\player.ini";
   trace("File.exists(vFile) : " + vFile + " exists? " + File.exists(vFile) );
   var iniFile = new Ini(vFile);
   var names = iniFile.getSectionNames();
   for (i = 0; i < names.length; i++){
      trace("getSection: "+names[i]);
      keys = iniFile.getSection(names[i]);
      for (j = 0; j < keys.length;j++){
         trace("SectionNames: "+keys[j]);
      }
   }
}
getAppIniSettings()
__________________
Awaiting Swf Kit V3
Reply With Quote
  #3 (permalink)  
Old 11-25-2005, 03:40 AM
Junior Member
 
Join Date: Jun 2003
Posts: 29
Default Re:Problem reading an INI file

Thanks for the reply.

However, with the code you've supplied, I'm still not getting any section names - the names array length returns 0.

The code is finding the ini file - the File.exists() returns true.

Almost like the ini file is empty - I've verified it isn't and is shown in my previous post.

Any ideas?

Thanks,

Steve
Reply With Quote
  #4 (permalink)  
Old 11-25-2005, 03:44 AM
Junior Member
 
Join Date: Jun 2003
Posts: 29
Default Re:Problem reading an INI file

I just modified the ini file to contain 3 sections. Now it reports that there are only 2 sections being read. It skips the first one (I previously only had 1 section so that's why I thought it wasn't being read in at all).

Anyone know why it doesn't retrieve the first section?

player.ini
Code:
[Resolution]
width=1024
height=768
[Resolution2]
width=1024
height=768
[Resolution3]
width=1024
height=768
Reply With Quote
  #5 (permalink)  
Old 11-25-2005, 05:27 AM
Senior Member
 
Join Date: Dec 2002
Posts: 2,015
Default Re:Problem reading an INI file

Klutsh's code works very well besides a small problem, thank you, Klutsh.

Code:
function getAppIniSettings(){
  var vFile= "C:\\testit.ini";
  trace("File.exists(vFile) : " + vFile + " exists? " + File.exists(vFile) );
  var iniFile = new Ini(vFile);
  var names = iniFile.getSectionNames();
  for (i = 0; i < names.length; i++){
      trace("getSection: "+names[i]);
      keys = iniFile.getSection(names[i]);
      for (j = 0; j < keys.length;j++){
        trace("SectionNames: "+keys[j]);
      }
  }
}

getAppIniSettings();
The getSectionNames method will get all the section names, the result of the above code is

Code:
File.exists(vFile) : C:\testit.ini exists? true
getSection: Resolution
SectionNames: width=1024
SectionNames: height=768
getSection: Resolution2
SectionNames: width=1024
SectionNames: height=768
getSection: Resolution3
SectionNames: width=1024
SectionNames: height=768
Reply With Quote
  #6 (permalink)  
Old 11-25-2005, 01:49 PM
Junior Member
 
Join Date: Jun 2003
Posts: 29
Default Re:Problem reading an INI file

Thanks again for the reponses.

I found the problem I was having.

At least on my system, using notepad to create the ini, the getSections will retrieve all sections except for the first one. If the ini file begins with a blank line, getSections() results in all sections being retrieved, included the first one.

Strange.

I receive the following output based on the player.ini described in a previous post:


FSCommand("FFish_Run", "Initialize")
File.exists(vFile) : C:\Projects\ccg\FlashTemplate\player.ini exists? true
getSection: Resolution2
SectionNames: width=1024
SectionNames: height=768
getSection: Resolution3
SectionNames: width=1024
SectionNames: height=768

Notice the first "Resolution" section is not being traced back.

Anyone else see this?

Thanks,

Steve

FYI:
player.ini
Code:
[Resolution]
width=1024
height=768
[Resolution2]
width=1024
height=768
[Resolution3]
width=1024
height=768
Reply With Quote
  #7 (permalink)  
Old 11-26-2005, 07:51 PM
Junior Member
 
Join Date: Apr 2005
Posts: 8
Default Re:Problem reading an INI file

Here's a different take on doing the same thing

Code:
function getAppIniSettings(){
  var vFile= "C:\\Projects\\player.ini";
  trace("File.exists(vFile) : " + vFile + " exists? " + File.exists(vFile) );
  var iniFile = new Ini(vFile);
  var names = iniFile.getSectionNames();
  for (i = 0; i < names.length; i++){
      trace("Section Name: "+names[i]);
      keys = iniFile.getSection(names[i]);
      for (j = 0; j < keys.length;j++){
        var inikey = keys[j].substr(0,keys[j].lastIndexOf("="));
        var inivalue = keys[j].substr(keys[j].indexOf("=")+1,keys[j].length);
        trace("Key Name: "+inikey+", Key Value: "+inivalue)
      }
  }
}
getAppIniSettings();
To get the actual keys value for use though use something like
Code:
var iniFile = new Ini("C:\\Projects\\player.ini");
var Rwidth = iniFile.getString("Resolution", "width");
var Rheight = iniFile.getString("Resolution", "height");
or for access to integars
Code:
var iniFile = new Ini("C:\\Projects\\player.ini");
var Rwidth = iniFile.getInt("Resolution", "width");
var Rheight = iniFile.getInt("Resolution", "height");
I've package what I used to run and test the top script
Download it: http://www.x-projects.org/readini.rar(1.12MB)
__________________
Awaiting Swf Kit V3
Reply With Quote
Reply

Was this information helpful?    Yes No



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 02:04 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.