-
XML to flash as2
ok. I have a lot of data to be passed into flash so I decided to use xml parssed from a database using php.
I got the xml into flash with the following code:
Code:
var my_xml = new XML();
my_xml.ignoreWhite = true;
my_xml.onLoad = function(success) {
if (success) {
trace(this);
}
};
my_xml.load("http://www.800score.com/flashdatatest.php");
This outputs the following:
Code:
<?xml version="1.0"?>
<entries>
<entry>
<date>2010-07-29</date>
<currentQuestion>1</currentQuestion>
<yourans>4</yourans>
</entry>
<entry>
<date>2010-07-29</date>
<currentQuestion>2</currentQuestion>
<yourans>2</yourans>
</entry>
<entry>
<date>2010-07-29</date>
<currentQuestion>3</currentQuestion>
<yourans>3</yourans>
</entry>
<entry>
<date>2010-07-29</date>
<currentQuestion>4</currentQuestion>
<yourans>3</yourans>
</entry>
<entry>
<date>2010-07-29</date>
<currentQuestion>5</currentQuestion>
<yourans>3</yourans>
</entry>
<entry>
<date>2010-07-29</date>
<currentQuestion>6</currentQuestion>
<yourans>3</yourans>
</entry>
<entry>
<date>2010-07-29</date>
<currentQuestion>7</currentQuestion>
<yourans>4</yourans>
</entry>
<entry>
<date>2010-07-29</date>
<currentQuestion>8</currentQuestion>
<yourans>5</yourans>
</entry>
<entry>
<date>2010-07-29</date>
<currentQuestion>9</currentQuestion>
<yourans>2</yourans>
</entry>
</entries>
my question is how do I get from there to arrays of values ie
currentQuestion array
yourans array
date array
?
Keep in mind that the amount of xml data will increase and decrease depending on how many questions the user answers.
I will be adding more xml data to the real thing...this is only proff of concept trial.
Thanks in advance
-
here's a link to get you started.
gparis
-
ok this is great to get me started however, is there a way to loop through the elements of the xml file in order to equate them to the appropriate array in flash?
-
It's in that link i gave you.
gparis
-
ok that worked great for getting the xml data into flash HOWEVER,
I have to post data to the php page before I get the xml into flash
WHat I have to post is the username, email, test name, and test number.
Is there a way to post data to the php page and get the xml data from the php page at the same time?
the data needs to be in array format, because that is how it comes from the mysql server.
Here is a workflow of what I need:
user logs into test (cookies are droped for username and email address)
those cookies are brought into flash (already done)
they are sent to the php page
the php page pulls the correct test from the database using username and email address.(done)
the php page then creates the xml data (done)
the xml data is transfered to flash(done)
I tried using sendAndLoad() and it didn't work.
ANy other ideas?
-
-
sendAndLoad() is the correct approach.
I guess it depends a on bit on how things are set-up..
are you sending a 'var' (string) to the php script to validate/get the correct XML data returned?
Im a bit confused on where you are.. since it looks like you have everything checked as working?
but you need to either create a new obj. (like an XML object) to handle the returned data
example:
Code:
var toPHP:LoadVars = new LoadVars();
var toPHP.onLoad = function(success){
if(!success){
trace("Data Not sent properly");
}else{
trace("data sent properly");
}
}
var fromPHP:XML = new XML();
fromPHP.ignoreWhite = true;
fromPHP.onLoad - function(success){
if(!success){
trace("XML NOT SENT");
}else{
trace("XML SENT....PARSING NOW.");
}
}
toPHP.userName = userName.text;
toPHP.passWord = passWord.text;
toPHP.sendAndLoad("www.somedomain.com/phpscript.php", fromPHP, "POST");
form there you can loop through your XML data like normal.. adding/pushing any/all data from the XML doc to an array/object array for accessing easier later if you desire.