Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Sep 2008
    Posts
    106
    Thanks
    27
    Thanked 3 Times in 3 Posts

    Question Is there something in Flash similar to Dreamweaver's Repeat-Region?

    Hello,
    I am trying to show the contents of an sql database table, in a flash page. I use a php file for this and some actionscript (2.0) code to do this.

    Code:
    var all_news = new LoadVars();
    
    all_news.load("http://localhost/test/news.php");
    all_news.onLoad = function(success){
    	if(success){
    		title_txt.text = all_news.news_title;
    		news_txt.text = all_news.news_text;
    	} else title_txt.text = "error";
    }
    I need to find a way to show all contents of the table, one after another, not just the first row and I wonder if there is something like Dreamweaver's Repeat Region, in Flash? An automatic mechanism to do easily what I want.

    Do have something to propose? Any ideas?
    Last edited by ktsixit; 12-10-2008 at 10:32 AM.

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    I would suggest that you use PHP to export the data in XML format, and then import it into Flash. You can use the PHP file to make the XML file on the fly, so you don't need to actually create a digital copy of the XML file and then link to it. There are some tutorials about XML and Flash in my signature link to tutorials.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • Users who have thanked gnomeontherun for this post:

    ktsixit (12-10-2008)

  • #3
    Regular Coder
    Join Date
    Sep 2008
    Posts
    106
    Thanks
    27
    Thanked 3 Times in 3 Posts
    I don't really want to mess with xml, it's a simple task. What I actually test right now is the following:

    php.file:
    Code:
    mysql_select_db($database_test_news, $test_news);
    $query_news = "SELECT * FROM news ORDER BY id DESC";
    $news = mysql_query($query_news, $test_news) or die(mysql_error());
    
    $totalRows_news = mysql_num_rows($news); 
    $rString ="&n=".$totalRows_news;
    
    for ($i=0; $i< $totalRows_news; $i++){
    	$row = mysql_fetch_array($news);
    	$rString .='&news_id'.$i.'='.$row['id'].'&'.'&news_title'.$i.'='.$row['title'].'&'.
    	'&news_text'.$i.'='.$row['text'].'&';
    }
    
    echo $rString.'&';
    .fla file:
    Code:
    var all_news = new LoadVars();
    
    all_news.load("http://localhost/italianjob/news.php");
    all_news.onLoad = function(success){
    	if(success){
    		
    		for(i=0; i<all_news.n; i++)
    		{
    			title_txt.text += all_news.news_title.toString() + i;
    			news_txt.text += all_news.news_text.toString() + i;
    		}
    	} else title_txt.text = "error";
    }
    where title_txt and news_txt are dynamic text fields. But the result I get is

    NaNNaNNaN

    I can'r find where the problem is. I would really appreciate if you took a look of the code above and give me some ideas

  • #4
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Well I don't know if you can avoid XML in this case. You have two options that I can think of, and XML is the best. The other option is to have your PHP format your data like this:

    item1|item2|item3

    and then split the string in Flash based on the separator "|". So you would have to import the string, split it, and then place it in proper arrays. However that seems much more delicate than making your PHP send XML to Flash.

    The reason it is not a simple task is that Flash is not able to accept arrays that would make this simple.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • Users who have thanked gnomeontherun for this post:

    ktsixit (12-10-2008)

  • #5
    Regular Coder
    Join Date
    Sep 2008
    Posts
    106
    Thanks
    27
    Thanked 3 Times in 3 Posts
    I thought tis would be quite simple but it seems that nothing is simple in flash....
    Can you at least give me that useful tutorial url of yours, because i can't find it. The one with xml - flash thing

  • #6
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    http://www.kirupa.com/web/xml/index.htm

    Yes, I understand sometimes simple things are hard. It has to do with the nature of Flash as starting as an animation platform (primarily) and then evolving now into basically a programming language.

    This is not too difficult though once you get the basic functions in there. Let us know your progress!
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • Users who have thanked gnomeontherun for this post:

    ktsixit (12-10-2008)


  •  

    Posting Permissions

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