View Full Version : Is there something in Flash similar to Dreamweaver's Repeat-Region?

12-10-2008, 09:20 AM
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.

var all_news = new LoadVars();

all_news.onLoad = function(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?

12-10-2008, 10:38 AM
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.

12-10-2008, 11:12 AM
I don't really want to mess with xml, it's a simple task. What I actually test right now is the following:


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'].'&'.

echo $rString.'&';

.fla file:

var all_news = new LoadVars();

all_news.onLoad = function(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


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 :)

12-10-2008, 01:34 PM
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:


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.

12-10-2008, 01:44 PM
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 :(

12-10-2008, 02:54 PM

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!