Hi, I am trying to load data from a file and put it in a comboBox. The coding I am using should work on platforms like Java and C, but I can't understand why on flash (since the coding style is like Java) it doesn't want to work. First of all i created a text file called "sections.txt" and the data inside it is as follows: &Ammount=3 &ele1="Hello 1" &ele2="Hello 2" &ele3="Hello 3" Then I used the following code to extract the data from the file: loadText = new loadVars(); loadText.load("sections.txt"); loadText.onLoad() = funtion(success){ // int(this.Ammount) is used to parse // string "3" to an integer number. for(i=1; i < int(this.Ammount); i++){ // populating comboBox with elements. _root.combo.addItem((this.ele+""+i),(this.ele+""+i)) // this.ele+""+i should become this.ele1 and thus load // the data found in the section &ele1, i.e. - "hello 1" } } The problem with the above code is that int(this.Ammount) is returning a 0 (Zero) and thus the loop never starts. And when I tried to inser a fixed number (ex: 3) all that is inserted in the combo bix is the value of i and not this.ele+""+i. I can't understand what is the problem since the concatination seems quite clear for me. I cant use XML() class coz i am loading from another flash file and it seems this class does not suport that, coz it loads nothing. I thought whether there is any way to travers the text file like this.next(i know this doesn't work). Thanks to all in advance, And i'll be very greatfull for any answers about the topic. Thanks!
alter your text file to - &Ammount=3& &ele1=Hello 1& &ele2=Hello 2& &ele3=Hello 3& and use this loop in your onLoad - for(var iv=1; iv <=this.Ammount; iv++){ elem = this["ele"+iv]; trace(elem); _root.combo.addItem(elem,elem); } hth
Thanks I'll try that ... I tried doing it with XML() class and seems to have worked fine, however i prefer the method you gave me since the code is more readable.
Hi again! I tired using the code u suplied but still had some problems with those two parts. When I do this.Ammount it still always return a 0. however the most important problem is when using this[""+category]. category is a variable that stores the text i want to load! ... This returns nothing!
try this MX6 file, hope it helps, http://www.jackleaman.co.uk/temp/sections.zip if not, try - maxN = this.Ammount*1; for(var iv=1; iv <=maxN; iv++){ .. }
:) I just implimented the code that you gave me and it worked just fine in my .swf file!
Don't see what you're looking for? Try a search.
|