Uplaod the fla and txt file, put them in the same directory, open the fla and render. You will see the listbox populates with more items then fileURL has in it.
fla
I knew about the &TotalNames=4& in the text file. I was trying not to use it because I am using perl/cgi to write the new phone number to the txt file; and I don’t know how to make &TotalNames=4& also write to the txt file and count up with the amount of new arrays.
So, do you know a little perl programming, or how else can I look at the Array length of my text file?
I don’t know if this will be the best way of doing it or not, but here you go…
if (success)
{
tmp = file.toString();
for (i = 0 ; i < tmp.length ; i++)
{
if (tmp.charAt(i) == '&')
{
cnt++;
}
}
cnt = (cnt - 1) / 6;
myArray = new Array();
for (i = 0; i < cnt; i++)
{
var firstName = eval("this.firstName" + i);
var lastName = eval("this.lastName" + i);
var phoneNumber = eval("this.phoneNumber" + i);
var eMail = eval("this.eMail" + i);
var Address = eval("this.Address" + i);
var webSite = eval("this.webSite" + i);
myArray* = [firstName, lastName, phoneNumber, eMail, Address, webSite];
var DataProvider = {firstName:myArray*[0], lastName:myArray*[1], phoneNumber:myArray*[2], eMail:myArray*[3], Address:myArray*[4], webSite:myArray*[5]};
listbox.addItem(firstName + " - " + LastName, DataProvider);
trace(i);
}
}
Right there… I am looping through the ‘tmp’ to find the occurances of ‘&’… If you manually count it, it will say 25… You have 24 &s that divides each fields and the last one for the onLoad function…
So… I have this, cnt = (cnt - 1) / 6;, that deletes one onLoad’s & and divides it with six fields you have… which returns four records… Does this make sense to you???
One thing… If you count the number of & sign inside your text file, you will see more than 25… Flash just gets rid of unnecessary ones when the content of the text file is imported…
Perl… He… It’s been a while since I didn’t touch any Perl script, so I’ll just pass… Though what you are looking for in Perl script is basically add numbers when for loop is executed and then print out that at the end of other print commands…
Works well: nice idea to loop though the occurrences of “&'s” and count them; But as the text file grows the script takes longer and longer to run. No big deal it will do the job for now, untill I get php down.
Yup… It can be problematic when the data gets larger… and that is why you gotta supply the number of records from the Perl script(or PHP soon maybe???)…
Why don’t you show us your Perl script??? I will see what I can do… No promises, though…
I’ve been looking for documentation on this topic, no luck.
I took out the full path to my txt file, not worried about you, but I don’t like the idea of everyone having access to my cgi-bin.
The variable in the Perl script called $mAlength is = to cnt rounded down. This is so each array in the txt file is labeled 1,2,3,4.
Thanks in advance for taken a peek at the Perl script.
I can’t up load cgi file here so I’ll turn it into a txt file.
How have you been??? Everything is alright, right??? Didn’t know you were in the Kirupa…
Um… If your mouth gets that big, my dogs will love to lick it…
waffe…
Yup… I totally understand that… No worries…
If you know the variable name, just print it one more time before you close the file… Something like this…
Im doing good how about you? Its been slow going after the re-death of WH. Mostly Ive been hanging around here… well first FK, then here. heh. Kirupa is fast, ad-free and has some decent good fun people. So currently, its my home away from home. Glad you’ve decided to step in and help out a little here too.
I could do it that way but I would still be using the “&” counter code in flash, to generate the cnt variable, which mAlength equals. As you said before, the best way to do this would have perl generate the array count. Which I would assume would be quite simple if I knew the Perl command.
How can Perl read the array count in the text file?
Glad to hear that you are alive and kicking… I’m good I guess… I got a new job last october and I felt like I have been abused by the owner, so I quit the job and I’m staying home with my wife and dogs ever since this february… Just trying to learn some more of Flash and PHP as much as I can while I have time…
I’ve been lurking around AS.org after that since that’s the first place I have visited among the Flash forums… And found out that Kirupa has a forum too… (Kinda late and slow, eh???) So, I thought that I’d visit and do what I can do while I have time…
But I have some problem with Kirupa flankly… I don’t know why, but IE just hangs with the browser which shows Kirupa if I stay long… (I am not kidding here though…) I just can’t figure out why… There is no (visible) Flash stuff on the screen since there is no ad here… The menu on the top is the only Flash I see on this browser, but if I stay here about 10 - 15 minutes, I get to see the dead IE browser… Not a clue why it is, but that’s what is happening to me…
Um… I heard a rumor from somebody else that WH is rebuilding the site… Don’t know if it is true or not, know any news about WH??? I was going to scrap all of Sx’s thread when the WH was up… Dang… Never thought that the site was going offline again that quick…
Ah… My dogs… They don’t really listen to me when they see something to eat…
I have checked the Perl script and I didn’t see how you are getting the lists of data into the Perl… What you have was some sort of form, which was outside source that has been parsed to the Perl… How does that structure going??? Can you tell me that???
I was meaning to append the counter at the end of the text file after generating the lists of data… That is the only way to do it efficiently… You could run another Perl script that goes through the list of data and send the counter back to Flash, but that’s like you are doing the same thing twice…
i only skimmed this thread so please forgive me if i repeat anything.
as you’re discovering, you can’t import arrays from a txt file, only strings. i usually use a delimiter, and then split the string into an array once it’s imported into flash.
so you might change your perl script to echo something more like:
phoneBook=zzzzz:zzzzz:zzzzzzz|zzzzz:zzzzz:zzzzzzz| … etc
in flash (are you using a loadVars object?):
book = new LoadVars();
book.onLoad = function(){
_root.phoneBook = this.phoneBook.toMultiArray("|",":",["first","last","num"]);
}
book.load("getPhoneBook.cgi");
String.prototype.toMultiArray = function(d0,d1,labels){
var a,b,i,j,o,ma = [];
a = this.split(d0);
for(i in a){
b = a*.split(d1);
o = {};
for(j in b){
o[labels[Math.min(j,labels.length)] = b[j];
}
ma.push(o);
}
return ma;
}
be warned that the long strings will cause a pause while flash slogs through it, check into branden halls string replacement if this becomes a problem: http://chattyfig.figleaf.com/~bhall/code/string.as
I think I know what you talking about. It is a second file that goes along with the first cgi file I uploaded. Here it is. So, just to make sure we are on the same track, we are trying to generate the array count from Perl, not flash? You accomplished the flash end with the “&” counter, but we know that becomes a bit slow if the file gets to big, like 10k.
So, to sbeener, is the code you gave me a rendition of Cyan Blue’s “&” counter? If it is thanks, but I think the true quest here is to be able to generate the array count from perl.
the method i posted takes a string and splits into an array of objects using delimiters and object labels that are passed as arguments.
the error checking isn’t very good, i realise looking at it now that it’s really important to pass it an array of labels that is the right length (doh!). i meant for it to be a little less error prone. oh well.
it’ll work and you could split the iterations into an onFrameEnter event rather than a for loop if you want to avoid a hang while the string is parsed. you could even have a meter, ‘loading address book’, or something.
any data you pass into flash will be strings. counting the number of &'s won’t prevent you from having to do all that string parsing, just change the way you go about it.
also, if your loadVars object only contains the address book, a for in loop will give you the number of variables (+ the onload event, but what’s one more or less between friends?).
if you need a scalable solution, say >1000 records or so, you might want to keep as much of it in perl/php as possible. ie. have your backend do all the parsing and only send flash the requested record. however, that might be a lot more development than you’re looking to do, i mean, you may as well database it at that point.