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, 12:57 PM   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
actionscript for loop doesn't work properly

Code:
var all_news = new LoadVars();
all_news.load("http://localhost/website/news.php?");
all_news.onLoad = function(success){
	if(success){
		for(i=1; i<=all_news.total; i++)                    //all_news.total = 3
		{	var this_new = new LoadVars();
			this_new.load("http://localhost/website/news.php?id="+i);
			trace("http://localhost/website/news.php?id="+i);
			this_new.onLoad = function(success){
				if(success){
					trace(this_new.news_title.toString());
					trace(this_new.news_text.toString());
				}else trace("error");
			}
		}
	}else trace("error");
}
this code is about getting data from a php file. The output it gives is:
http://localhost/website/news.php?id=1
http://localhost/website/news.php?id=2
http://localhost/website/news.php?id=3
undefined
undefined
undefined
undefined
title 3
text 3


but why is this happening? Shouldn't it be like this?>>
http://localhost/website/news.php?id=1
undefined
undefined
http://localhost/website/news.php?id=2
undefined
undefined
http://localhost/website/news.php?id=3
title 3
text 3
ktsixit is offline   Reply With Quote
Old 12-10-2008, 02:08 PM   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
It does work, it just functions differently than you might think. All of the data appears to be getting processed and you could put it into an array.

I think the issue is that sometimes Flash isn't always able to grab data from external places and kind of 'queues' it up. So in this case, it does the parts of the loop that don't have an event handler (onLoad) and puts the onLoad afterwards.
__________________
jeremy - gnomeontherun
Educated questions often get educated answers, and simple questions often get simple answers.
gnomeontherun is offline   Reply With Quote
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 04:45 PM.


Advertisement
Log in to turn off these ads.