-
Hi,
I am trying to put the retrieved textvalues into an array like the following way(see below). I cant get it done, so I hope someone can assist me in this
----------- code --------------------------------
loadVariablesNum("target.txt", 0); //loading the records
set (targetCount,targetCount); //total number of records
for (i=1; i<TargetCount; i++) {
set (target[i],target[i]); //creating the flash variables }
personDB =new Array();
personDB.push({id: "01",name:"Matthias Kannengiesser",stadt:"Stuttgard",plz:13234 });
So my question is:
1) How can I put e.g. the values of taget1, target2 etc. into the section id: " "?
2) making the array loop, based on the given targetcount, so that the array gets filled
Or is there perhaps a smarter way of doing this?
cheers
Patrick
-
If you are prepared to change your text file, this is much easier than you might think.
If your text file reads:
myVar=value1~value2~value3~value4
and so on, then this code:
Code:
myArray = myVar.split("~");
will automatically return an array containing the elements between the '~' symbols.
Is there any reason why you can't do it that way?
-
Dear Sualdam
My textfile looks something like this:
&name1=john&name2=frank&name3=stuart&age1=24&age2= 34&age3=28&city1=Amsterdam&city2=rome.....(I would be able to alter the sequence if necissary)
I basically want to create several rows that I can, like in the script above, add to the array.
I am not very good at actionscript, but would it be possible to for you to 'translate' it in a way, to make it look like the array above?
I hope you can help me
kind regards
Patrick
[Edited by cuboctahedron on 07-21-2002 at 10:16 AM]
-
In your text file:
name=john~frank~stuart&age=24~34~38
In Flash, load the variables in the usual way then - in a later frame, not in the same frame as your load variables instruction:
Code:
nameArray = name.split("~");
ageArray=age.split("~");
What you will now have is:
name[0] = john
name[1] = frank
name[2] = stuart
and
age[0] = 24
age[1] = 34
age[2] = 38
If you wanted to get clever, you could create a two-dimensional array from text:
myVar=john!24~frank!34~stuart!38
And do two splits using the '~' and '!' characters. You'd end up with:
myArray[0][0] = john
myArray[0][1] = 24
myArray[1][0] = frank
myArray[1][1] = 34
myArray[2][0] = stuart
myArray[2][1] = 38
That's a bit more involved, but easy enough.
-
So combining:
personDB =new Array();
personDB.push({id: "01",name:"Matthias Kannengiesser",stadt:"Stuttgard",plz:13234 });
with:
name[0] = john
name[1] = frank
name[2] = stuart
age[0] = 24
age[1] = 34
age[2] = 38
would result in(?...):
personDB =new Array();
for (number=1; i<TargetCount; number++) {
personDB.push({name:name[number],age:age[number] });
}
I am sorry that your dealing with a newbie here (I am pretty good with other language). I am just rying to learn here..
-
You lost me
What are you trying to do? Add the details from the textfile to personDB... no, that doesn't look right, I'm just guessing.
Can you explain a bit more?
-
O.k...
I've downloaded (here at flashkit.com) a movie.(fsonsort.fla)
I cant recall the exact url I'm afraid.
(found it http://www.flashkit.com/movies/Scrip...783/index.php)
It displays, in 4 columns recordsets(incl ID), that can be sorted Ascending or descending.
The given recordsets are however static texts
The part of the scripts where he collects the data is shown below:
-----------------------------------------------------
// How to use sortOn()
// Made by Matthias Kannengiesser (Madokan)
personDB =new Array();
personDB.push({id: "01",name:"Matthias Kannengiesser",stadt:"Berlin",plz:13234 });
personDB.push({id: "02",name:"Caroline Kannengiesser",stadt:"Berlin",plz:13222 });
personDB.push({id: "03",name:"Hendrik Sichermann",stadt:"Stuttgart",plz:19299 });
personDB.push({id: "04",name:"Frank Klein",stadt:"Bremen",plz:29299 });
personDB.push({id: "05",name:"Norman Bauer",stadt:"Hannover",plz:37179 });
personDB.push({id: "06",name:"Daniel Benson",stadt:"San Diego",plz:97179 });
personDB.push({id: "07",name:"Michael van Hollen",stadt:"Housten",plz:78179 });
personDB.push({id: "08",name:"Alexeij Drankowski",stadt:"Moskau",plz:67179 });
personDB.push({id: "09",name:"Matthias Kannengiesser",stadt:"Berlin",plz:13234 });
personDB.push({id: "10",name:"Caroline Kannengiesser",stadt:"Berlin",plz:13222 });
personDB.push({id: "11",name:"Hendrik Sichermann",stadt:"Stuttgart",plz:19299 });
personDB.push({id: "12",name:"Frank Klein",stadt:"Bremen",plz:29299 });
personDB.push({id: "13",name:"Norman Bauer",stadt:"Hannover",plz:37179 });
personDB.push({id: "14",name:"Daniel Benson",stadt:"San Diego",plz:97179 });
personDB.push({id: "15",name:"Michael van Hollen",stadt:"Housten",plz:78179 });
personDB.push({id: "16",name:"Alexeij Drankowski",stadt:"Moskau",plz:67179 });
// Sortieren ASC
function sortieren(kat) {
personDB.sortOn(kat);
id = name = stadt = plz = "";
for (i=0;i<personDB.length;i++) {
id += personDB[i]["id"]+"\n";
name += personDB[i]["name"]+"\n";
stadt += personDB[i]["stadt"]+"\n";
plz += personDB[i]["plz"]+"\n";
}
}
// Sortieren DES
function dsortieren(kat) {
personDB.sortOn(kat);
id = name = stadt = plz = "";
for (j=personDB.length-1;j>=0;j--) {
id += personDB[j]["id"]+"\n";
name += personDB[j]["name"]+"\n";
stadt += personDB[j]["stadt"]+"\n";
plz += personDB[j]["plz"]+"\n";
}
}
sortieren("id")
-------------------------------------------------
What I am trying is to replace these (data)recordset-items with database information (provided in a textfile e.g.)
I hope this makes it bit bit clearer?
[Edited by cuboctahedron on 07-21-2002 at 11:01 AM]
-
Ay caramba!
If I get time I'll have a look - but that's a whole project
To clarify some more - you want to get this information from a text file and sort it?
You may not have to use that other sort routine, you know.
-
Well loading variables from PHP (or any other language I suppose) works about the same way.
I just proposed a text file to make things more clearer.
Well should you be able to have some time for it I'll be very happy.
Of course I'll try to figure it out also, and post the answer should it be available.
Anyhow thank you for your time
cheers
Patrick
-
can i chime in ? thanks
i also have a ext file that goes like ,
varname=blah blah,ha ha,he he
and have seperated with , instead of ~
ok no problem but are there any other characters you cant have in the the txt file ? or does it not matter ?
cheers
-
Funny,
today I am working with the same matter of textfiles,
anyhow, indeed some characters must be ' replaced' before flash can read it: e.g
1) the '&' sign 'deloitte & touche' must become 'deloite %26 touche'
2) 6+6=12 must become 6 %2b 6 %3d 12
also if you have an array divided bij '~' or something else i would also replace that character from the text '~' would than be %7E
I am currently using PHP to create dynamic flash sites, but I find it a big hassle using using flash. I was hoping it would be more down to earth.
Problem I have are:
- populating drop downs and assigning a default value
If you know any good tutorial on this please let me know.
cheers
Patrick
-
If you are using the split method then you can use any character as the separator...
...except the reserved ones, with '&' being the best example.
I'd avoid %, but you can have -, + *, <, >, /, £, !, ^, $, (, ), and so on Plus any alphabetical or numerical character. As long as they aren't used in the variables, you are safe.
I can't see how that would not be enough and not being able to use & or % end up being an issue
The codes used to display reserved characters are explained here (URL Encoding):
http://www.macromedia.com/support/fl...l_encoding.htm
-
I think it's important using the % etc.
If e.g. a databasefield (or textfield whatever) contains a & sign or ~ etc. within it's own field, the array would get jammed
example:
textfile: looks like '&test1 =one|two|three'
Flash reads it like "one|two|three"
But supposes the 'one' would become 'on|e' than flash would read it like "on|e|two|three"
So I prefer to make thing 'idiot proof' so that no mistakes can happen.
If you are using PHP you can use the urlencode() syntax, and than you are really save
-
okay, sualdam, i tried what you said at the beginning, about myVar.split but it doesnt work for me. my coding is short so here it is.
{
Frame 1:
size = 5;
loadVariablesNum ("numbers.txt", 0);
loadVariablesNum ("mess.txt", 0);
messages = new Array(size);
Frame 2:
messages = myVar.split("~");
message = String(size) + " " + String(messages[0]);
//message is a dynamic text box
numbers.txt:
size=2
mess.txt:
myVar=Hello~How Are You~Click Here
}
The problem is that even though size is equal to 2 (I debugged) message has 5 at the beginning. Also, messages is undefined, so there is nothing else displayed in the text box. Is there a problem with how I am loading the variables or what?
Thanx a bunch, irf2k
-
irf2k
You don't need to declare the array when using split - it creates it automatically.
If you have a text file with:
myVar=123~456~789
Then:
Code:
anyArray = myVar.split("~");
will return an array called anyArray with three elements.
Is that what you meant?
(Sorry I didn't reply earlier - had to do yet another complete reinstall )
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|