A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: XML to flash as2

  1. #1
    Senior Member
    Join Date
    Jul 2002
    Location
    New Mexico
    Posts
    101

    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
    Last edited by Beyond Flash; 07-30-2010 at 12:29 AM.
    Beyond Flash
    Your one stop web shop
    http://www.beyondflash.net

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    here's a link to get you started.

    gparis

  3. #3
    Senior Member
    Join Date
    Jul 2002
    Location
    New Mexico
    Posts
    101
    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?
    Beyond Flash
    Your one stop web shop
    http://www.beyondflash.net

  4. #4
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    It's in that link i gave you.

    gparis

  5. #5
    Senior Member
    Join Date
    Jul 2002
    Location
    New Mexico
    Posts
    101
    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?
    Last edited by Beyond Flash; 07-31-2010 at 04:03 PM.
    Beyond Flash
    Your one stop web shop
    http://www.beyondflash.net

  6. #6
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    try here

    gparis

  7. #7
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center