...

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



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


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?

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

ktsixit
12-10-2008, 10: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:

php.file:

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:

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

gnomeontherun
12-10-2008, 12: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:

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.

ktsixit
12-10-2008, 12: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 :(

gnomeontherun
12-10-2008, 01:54 PM
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!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum