A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Loading text Problem !!!

  1. #1
    Member
    Join Date
    Aug 2005
    Posts
    42

    Loading text Problem !!!

    Hello

    I have a database that I store some data. I want to view this data in my flash project.
    The text is not appearing the way it should. For some reason its adding for each enter one more enter than it should.

    I have a php file that takes the data from the database and it makes an XML structure code.


    For example:
    ----------------------------The way the text should be written---------------------------------
    Hello world
    Hello world
    -----------------------------And this is how the text is appearing-----------------------------------------------
    Hello world

    Hello world
    ----------------------------------------------------------------

    If you have any idea please help ! ! !
    Thank you


    Actionsctipt:
    Code:
    
    var theXML:XML = new XML();
    theXML.ignoreWhite = true;
    
    theXML.onLoad = function() {
    	
    	var nodes:Array = theXML.firstChild.childNodes;
    	for(i=0; i<nodes.length; i++) {
    		
    		
    		my_txt2.text += nodes[i].firstChild.nodeValue + "\n";
    		
    	}
    	
    }
    theXML.load("http://localhost/PrimeMarine/prime TEST/1/con_flash4.php")

    php script:
    Code:
    
    <?php
    
    require("config.php");
    
    $connection = mysql_connect($db_host, $db_user, $db_password) or die("error connecting");
    mysql_select_db($db_name, $connection);
    
    
    $query = "SELECT * from news ORDER BY month desc";
    $result = mysql_query($query, $connection);
    
    
    
    
    
    
    
    echo "<?xml version=\"1.0\"?>\n";
    echo "<comments>\n";
    
    while ($line = mysql_fetch_assoc($result)) {
    
    echo "<item>" . $line["comments"] . "</item>\n";
    
    }
    
    echo "</comments>\n";
    ?>

  2. #2
    flashguy
    Join Date
    May 2005
    Location
    In the mountains
    Posts
    341
    Try to read it directly using loadVars instead XML...
    Normally I use XML just for direct XML fles reading from disk (no database).
    Visit my business at http://www.ballooncreator.com - Software Tool For Party Balloons Online Design!

  3. #3
    Senior Member
    Join Date
    Feb 2001
    Location
    On the fifth floor.
    Posts
    1,202
    Try to remove + "\n" from this line: my_txt2.text += nodes[i].firstChild.nodeValue + "\n";

  4. #4
    flashguy
    Join Date
    May 2005
    Location
    In the mountains
    Posts
    341
    Quote Originally Posted by sergwiz
    Try to remove + "\n" from this line: my_txt2.text += nodes[i].firstChild.nodeValue + "\n";
    Good point...
    Visit my business at http://www.ballooncreator.com - Software Tool For Party Balloons Online Design!

  5. #5
    Member
    Join Date
    Aug 2005
    Posts
    42
    I have finally managed to solve this problem
    With this:

    Code:
    var theXML:XML = new XML();
    theXML.ignoreWhite = true;
    
    theXML.onLoad = function() {
    	
    	var nodes:Array = theXML.firstChild.childNodes;
    	for(i=0; i<nodes.length; i++) {
    		
    		my_txt += nodes[i].firstChild.nodeValue + "\n";
    		
    		
    		
    	}
    	var my_txt = my_txt.split("\n").join("");
    	my_txt2.text = my_txt;
    	
    }
    theXML.load("http://localhost/PrimeMarine/prime TEST/1/con_flash4.php")
    But I still have another problem, before the text a word “undefined” appears.
    Why dose it shows the word “undefined” ?????
    Probably something is going wrong with the “for” statement.
    Thank you
    Last edited by spyrosk; 09-27-2006 at 03:35 PM.

  6. #6
    flashguy
    Join Date
    May 2005
    Location
    In the mountains
    Posts
    341
    "Undefined" means that you are trying to use an undefined var.
    Probably it is happening because you are doing:
    Code:
    my_txt += nodes[i].firstChild.nodeValue + "\n";
    before to define the my_txt var. Since it's undefined and you are using +=, you are joining the previous value of my_txt (undefined) with the loaded content.
    Visit my business at http://www.ballooncreator.com - Software Tool For Party Balloons Online Design!

  7. #7
    Senior Member
    Join Date
    Feb 2001
    Location
    On the fifth floor.
    Posts
    1,202
    It's better to use theXML.onData instead of theXML.onLoad

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