dcsimg
A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 23

Thread: I don't get my flash movie to read XML data

  1. #1
    Member
    Join Date
    Jul 2003
    Posts
    79

    I don't get my flash movie to read XML data

    please I need your help. I made a flash movie with an XML object called news. This XML object has to load a PHP document news.php, which in turn loads the required data from a MySQL database and then echoes it as XML data in order to be stored in news and parsed in Flash.

    When I call news.php directly from my browser and check the source code generated, I see it's the XML data as I want it to be. However, when I read it from Flash, the XML object doesn't seem to read it properly.

    I'm almost sure it's something about the character encoding because I sometimes use special characters, but I can't get it fixed.

    When I created the database, it was unicode encoded, but after this problem ocurred, I changed it to utf8. Now when PHP echoes the output XML code just after PHP retrieves the required data from MySQL, I use the PHP function utf8_encode() too (I think it has to be this way for Flash). I'm a bit confused about all this encoding stuff between MySQL-PHP and PHP-Flash. So I'm not sure if I'm doing it well.

    Could you please help me out?
    Last edited by Tigervlc; 09-22-2007 at 03:04 PM.

  2. #2
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    did you wrote in the header of the php stream that it is a xml file?- or did you just echo strings? e.g:
    PHP Code:
    <?php
    header
    ('Content-Type: text/xml');
    something else I found:
    http://www.jeroenwijering.com/?thread=3100

    does your flash code alone work with standalone xml files?

  3. #3
    Member
    Join Date
    Jul 2003
    Posts
    79
    Quote Originally Posted by renderhjs
    did you wrote in the header of the php stream that it is a xml file?- or did you just echo strings? e.g:
    PHP Code:
    <?php
    header
    ('Content-Type: text/xml');
    something else I found:
    http://www.jeroenwijering.com/?thread=3100

    does your flash code alone work with standalone xml files?
    Thank you for your help.
    I tried sending the header like you said and this way:
    header("Content-Type: application/xml; charset=UTF-8");

    but still nothing happens

    And yes, my code works perfectly with standalone xml files. In fact there's another Flash XML object which loads a menu from menu.xml. In this part the XML object reads perfectly the xml data and if I trace it, it's output just as I wrote it.

  4. #4
    Member
    Join Date
    Jul 2003
    Posts
    79
    This is my code:

    ACTIONSCRIPT (quoted like php to colour it):

    PHP Code:
    menuXML = new XML();
    menuXML.ignoreWhite true;

    menuXML.onLoad = function(success) {
        
    trace(menuXML); // works fine, no problem.
        // actions to place menu
    };

    menuXML.load("menu.xml");

    // ------------FOLLOWING PART DOES NOT WORK-------------------------

    // news reading

    news = new XML();
    news.ignoreWhite true;

    news.onLoad = function(success) {
        if (
    success) {
            
    trace("NEWS: " news);
        } else 
    trace("Couldn't load XML data");
        
    // actions to place news
    };

    news.load("news.php"); 
    PHP CODE:

    PHP Code:
    //... retrieving from MySQL database ...

    if ($res->num_rows 0) { // $res contains the result of the query
        
    header("Content-Type: application/xml; charset=UTF-8");
        
        
    $output "<news>\n";
        while (list(
    $id$title$content$date$image)=$res->fetch_array()) {
            
    $output .= "\t<piece id=\"$id\" title=\"".utf8_encode($title)."\" content=\"".utf8_encode($content)."\" date=\"$date\" image=\"$image\" />\n"// note that only title and content are susceptible to have special characters
        
    }
        
    $output .= "</news>\n";
    } else 
    $output "<news />";

    echo 
    $output;

    //... closing connection to database ... 
    When I run my flash movie, it outputs:
    Code:
    NEWS:
    it seems there has been success, but no xml data is shown.

  5. #5
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    even though it works fine always check if it succesfully was loaded otherwise it will pass as well if the file is not on the server, corrupted or whatever
    PHP Code:
    menuXML.onLoad = function(success) { 
        
    trace(menuXML); // works fine, no problem. 
        // actions to place menu 
    }; 
    to
    PHP Code:
    menuXML.onLoad = function(ok) { 
        if (
    ok){
             
    trace(menuXML); // works fine, no problem. 
        
    }
    }; 

    ok I guess I got it,- FLash itself can┤t load PHP stuff you need to test it in the browser- more the reason why you can┤t trace because the flash player in the browser doesn┤t display such (not below flash 9- for 9 there is actually a soltuion). So add a textfield that will display the results. I named with a instance name (not variable name!!) of "textfield". Try if it works (in the browser)

    to better debug try:
    PHP Code:
    // news reading 
    news = new XML(); 
    news.ignoreWhite true
    news.onLoad = function(success) { 
        if (
    success) { 
            
    textfield.text "NEWS: " news.toString(); 
        } else 
    trace("Couldn't load XML data"); 
    }; 
    news.load("news.php"); 
    besides that,
    does the php work propper,- do you have installed it on your system or started it?,- does the php in the browser display it propper and in Firefox for example display it as XML without any syntax errors?
    Just in case: if you dont have php installed on your system but only online try portable webapp without installation- it only requires a start and can be closed anytime without leaving any traces on the HD. The URL is:
    http://portablewebap.com/portablewebap.php

  6. #6
    Member
    Join Date
    Jul 2003
    Posts
    79
    I'm using Flash CS3 (Flash 9) so the trace action should work, but it doesn't. Anyway I tried your proposal and this is what I got in the text field:

    Code:
    NEWS: undefined
    so what I understand is that there's success reading the XML data, but it's undefined??

    I have PHP+MySQL installed in my HD under Apache server (XAMPP bundle).

    Even if I only pass one field with no special character (eg. id) the error still happens. Edited PHP code:

    PHP Code:
    //... retrieving from MySQL database ...

    if ($res->num_rows 0) { // $res contains the result of the query
        
    header("Content-Type: application/xml; charset=UTF-8");
        
        
    $output "<news>\n";
        while (list(
    $id)=$res->fetch_array()) {
            
    $output .= "\t<piece id=\"$id\" />\n"// Just one field (id) from the database, with no special chars, as an XML attribute.
        
    }
        
    $output .= "</news>\n";
    } else 
    $output "<news />";

    echo 
    $output;

    //... closing connection to database ... 
    when I call news.php from my browser, I get:

    Code:
    <news>
    	<piece id="3" />
    	<piece id="4" />
    	<piece id="5" />
    </news>
    it's well formed XML, but Flash doesn't read it properly.

    Also tried to save news.php, by means of Notepad, in ANSI (it was by default with Dreamweaver CS3), Unicode, and UTF-8, but no way.

  7. #7
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    like I said,- it only works in the browser,- not in the flash environment (security or whatever reason)

  8. #8
    Member
    Join Date
    Jul 2003
    Posts
    79
    I think you really can in the Flash environment as well. I got it in other program I made about an agenda.

  9. #9
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    at least in Flex I have to disable certain security barriers- always tested php with flash in the browser. If you come up with a solution that works in the Flash environment I┤d be interested as well.

  10. #10
    Member
    Join Date
    Jul 2003
    Posts
    79
    I hope someone helps me. I'm getting crazy! I don't know why it worked in a previous movie and not now. Is there any way to take total control on character encoding when debugging the program? or any function which shows some range of error codes for this? (Maybe although the XML load gets success, there's probably some error code stored somewhere).

  11. #11
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    well I think it doesn┤t get propper parsed in PHP - but rather because flash doesn┤t support it somehow- why dont you prepare the xml as standalone and first work with that,- test the other stuff in the browser

  12. #12
    Member
    Join Date
    Jul 2003
    Posts
    79
    No, it does support it Render, really. As I said above, I've got another program (an agenda with names, phone numbers, addresses and so) with its database, its PHP and its Flash, and it works. The trace action of XML data echoed from PHP and stored in Flash (sort of on-the-fly) does work, believe me.

    But not in this last program. I'm doing about the same but I can't seem to find the problem.

  13. #13
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    for testing purposes

    get news.php to write the output to an xml file -
    Code:
    $output="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\n";
    $output .= "<news>\n";
    while.......
    ......
    $file= fopen("test.xml", "w");
    fwrite($file, "$output");
    and load the xml file into your xml object -

    news.load("test.xml");

    does this method produce the correct result ?

  14. #14
    Member
    Join Date
    Jul 2003
    Posts
    79
    How do I perform it in order to call news.php and when it's executed, read test.xml?

    Anyway, I made your choice modified_dog (generating an XML file) by calling news.php from my browser, and afterwards I read the XML file generated by PHP. What I get is that the special characters appear encoded, same as when I read the echoed data from PHP, and I'm not sure if that's one of the reasons why Flash can't store them.

    These are some special characters and their encoding the way they appear in the XML file (I'm using Spanish):

    ˇ ---> ├│
    ˝ ---> ├▒
    ˙ ---> ├║
    ß ---> ├í

    Finally, once I've got test.xml generated, I change my Actionscript code in order to load the xml data from this file instead of the echoed xml code from news.php (I simply do the process you suggested, breaking it down, not at a time 'cause I didn't know how to). In this case, the data is read and stored in the XML object, at last, and that seems a progress, but it still appears encoded no matter if I trace it or if I show it on a text field.

    Some light on this?
    Last edited by Tigervlc; 09-23-2007 at 08:14 PM.

  15. #15
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    the only thing i can think of is to change to Latin based encoding -

    $output="<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n";

  16. #16
    Member
    Join Date
    Jul 2003
    Posts
    79
    By using

    $output="<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n";

    the speacial chars in xml appear even more encoded (like a double encoding or so).

    I did the same you suggested previous to your last post. And also deleted the utf8_encode() functions I had for attributes which might contain special characters. Seems they were a redundancy for I also had the line:

    $output="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\n";

    Then, your choice works and this time I get my special characters as they are. Special chars issue apparently solved.

    But I still can't get it "on-the-fly", that is when Flash reads the xml data directly from what PHP echoes.

  17. #17

  18. #18
    Member
    Join Date
    Jul 2003
    Posts
    79
    Quote Originally Posted by renderhjs
    My browser gets an error with that address, maybe you misspelled it.

    It was a false alarm

    Getting down to it...
    Last edited by Tigervlc; 09-24-2007 at 01:32 PM. Reason: false alarm

  19. #19
    Member
    Join Date
    Jul 2003
    Posts
    79
    renderhjs: thank you for your help , but I'm not loading anything from a different domain. It's everything local. Both the files news.php and the .fla (and its corresponding .swf) are even stored in the same folder. So I think that's not the question here.

    The question is this:

    I can't (locally) retrieve in Flash the xml data provided by php, which in turn retrieves it from a database, doing it "on-the-fly", without using an intermediary auxiliar xml file.

  20. #20
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    some other links, regarding the security model around XML as well:
    http://www.adobe.com/devnet/flash/ar...curity_03.html
    http://www.melbournechapter.net/word...ta-from-flash/

    I am not 100% sure but my guess is that the solution might be within those links,- as my projects suffered from the same- perfectly in the browser but not working at all in the Flash IDE environment.

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