i'm trying to create an array from the datas i'm getting with loadvariablesnum with my php file.
as i saw that the synthax to create an array was like new Array("data1","data2",etc), i've returned a line of result that look like this:
"bb","boubou","bb","kalou"
so if i name a textfield "connected" (which is the name of this variable), i have this string writen in it.
pb: if i make a :
connected2=new Array(connected);
ok i can see my array in my textfiel called connected2
and then i try to sort my values with:
connected4=connected2[0];
it returns nothing...someone may help about setting a flash array from values loaded from php (as it seems to be my problem)
txt = "a,b,c,d";
yourArray = txt.split(",");
trace (yourArray.length);
for (i in yourArray) trace (yourArray[i])
Now...
If u retrieving some data from php script and having it displayed like "bb","boubou","bb","kalou" u could try:
code:
someVar="bb","boubou","bb","kalou"; // from php script
newArray=someVar.split('"').join("").split(",");
trace (newArray.length)
for (i in newArray) trace (newArray[i]);
as i have no idea how are your script printing those data, I can only 'guess' the best way to do it.
If your php script doesn't return a variable and just return some data use LoadVars instead:
code:
var tmp = new LoadVars();
tmp.load ("yourFile.php");
tmp.onData = function ($d) {
newArray = $d.split('"').join("").split(",");
trace (newArray.length);
for (i in newArray) trace (newArray[i]);
}
var tmp = new LoadVars();
tmp.sendAndLoad ("connected_flash.php?" + randomnumber(), tmp, "POST"); tmp.onLoad = function (ok) {
if (ok) {
connectedx = this.connected;
connected3 = connectedx.split(",");
trace (connected3.length);
}
}
I supposed your problem is the loadVariablesNum coz u'r running all commands at once. If u use loadVariables u have to use a function (such as setInterval or getTimer) to check when the data get loaded and after that build your array.
so this duplicate my button as many times as i have a data line.My proiblem is that i don't manage to put the text on each button, with the line _root["myButton"+n].myButtonTextField.text = data[n];
my trace give me the values of each data[],so these values are present...may you help..? thx
thx again for your answer. the point is that my button is already a movie clip (the movie myButton is a MC containing the button)...have some more clue???
and thx for the details about loadvariablesnum..i didn't undersatand why it took so much time to load the datas (in general i had to wait a full movie loop to have them loaded)...whta would u use better than loadvariablesnum..?
hello again...thx for your help, this is working (almost) perfectly...
now i've got some other questions:
the aim of all this is the creation of a private chat with php...
so the query that retrieve the datas looks like this:
$query=mysql_query("SELECT * FROM chat_messages WHERE expediteur='$exp' AND dest='$dest' OR expediteur='$dest' AND dest='$exp' ORDER BY date DESC");
where "$exp" is me, and "$dest" is the person i'm talking to...so i'm calling this page this way in flash:
basically, i've send the exp and dest variables in the html page where i'm calling the swf movie...what i would like to do is to use the buttons we've created together to send the dest variable to the line i'm calling the php script, to retrieve the messages coming from this person (and additionnaly to switch my conversation screen to this person conversation)
so is it possible to send this variable like this for example:
another, personal question: where you coding php before using flash..? as the way you're handling variables in flash (with "$") is closer to php than what i saw before in flash...
dest = $data[$i];
loadVariablesNum("http://localhost/chat/messages.php? + randomnumber(), 0, "POST");
another, personal question: where you coding php before using flash..? as the way you're handling variables in flash (with "$") is closer to php than what i saw before in flash...
In fact I learned actionscript first. I started to learn PHP a couple months ago and then I saw how php handles variables (using '$'). But using '$' in my codes help me to identify variables, what makes the process to find some bug or error much more easy.
ok, but how to transmit the value of each returned line to my button MC..? in the script u sent me, i tryed to do the following, on the onclick frame of the button: