Go Back   CodingForums.com > :: Client side development > Flash & ActionScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-10-2008, 08:20 AM   PM User | #1
ktsixit
Regular Coder

 
Join Date: Sep 2008
Posts: 106
Thanks: 27
Thanked 3 Times in 3 Posts
ktsixit is an unknown quantity at this point
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..
ktsixit is offline   Reply With Quote
Old 12-10-2008, 09:38 AM   PM User | #2
gnomeontherun
Senior Coder

 
gnomeontherun's Avatar
 
Join Date: Sep 2007
Location: Houston
Posts: 2,846
Thanks: 10
Thanked 238 Times in 229 Posts
gnomeontherun will become famous soon enoughgnomeontherun will become famous soon enough
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.
gnomeontherun is offline   Reply With Quote
Users who have thanked gnomeontherun for this post:
ktsixit (12-10-2008)
Old 12-10-2008, 10:12 AM   PM User | #3
ktsixit
Regular Coder

 
Join Date: Sep 2008
Posts: 106
Thanks: 27
Thanked 3 Times in 3 Posts
ktsixit is an unknown quantity at this point
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
ktsixit is offline   Reply With Quote
Old 12-10-2008, 12:34 PM   PM User | #4
gnomeontherun
Senior Coder

 
gnomeontherun's Avatar
 
Join Date: Sep 2007
Location: Houston
Posts: 2,846
Thanks: 10
Thanked 238 Times in 229 Posts
gnomeontherun will become famous soon enoughgnomeontherun will become famous soon enough
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.
gnomeontherun is offline   Reply With Quote
Users who have thanked gnomeontherun for this post:
ktsixit (12-10-2008)
Old 12-10-2008, 12:44 PM   PM User | #5
ktsixit
Regular Coder

 
Join Date: Sep 2008
Posts: 106
Thanks: 27
Thanked 3 Times in 3 Posts
ktsixit is an unknown quantity at this point
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
ktsixit is offline   Reply With Quote
Old 12-10-2008, 01:54 PM   PM User | #6
gnomeontherun
Senior Coder

 
gnomeontherun's Avatar
 
Join Date: Sep 2007
Location: Houston
Posts: 2,846
Thanks: 10
Thanked 238 Times in 229 Posts
gnomeontherun will become famous soon enoughgnomeontherun will become famous soon enough
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.
gnomeontherun is offline   Reply With Quote
Users who have thanked gnomeontherun for this post:
ktsixit (12-10-2008)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:34 PM.


Advertisement
Log in to turn off these ads.