|
|||
|
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();
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 Any ideas? Thanks, Steve |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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();
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 |
|
|||
|
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 |
|
|||
|
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();
Code:
var iniFile = new Ini("C:\\Projects\\player.ini");
var Rwidth = iniFile.getString("Resolution", "width");
var Rheight = iniFile.getString("Resolution", "height");
Code:
var iniFile = new Ini("C:\\Projects\\player.ini");
var Rwidth = iniFile.getInt("Resolution", "width");
var Rheight = iniFile.getInt("Resolution", "height");
Download it: http://www.x-projects.org/readini.rar(1.12MB)
__________________
Awaiting Swf Kit V3 |
![]() |
Was this information helpful? Yes No
| Thread Tools | |
| Display Modes | |
|
|