[PHP->Flash]Problem with Arrays

Basically what I’m doing is pulling information from a MySQL database and putting into a string and then loading that information into Flash using LoadVars. I’ve used this tutorial to get me off the ground.

This is the PHP file (named posts.php) and [url=http://iamcolin.com/colin/php/phpstring.txt]here is the string is outputs.

All should be well and good from there, I think. There are four separate things for each entry’s information: ID, title, content, and date.

Here is the Actionscript code that loads it and displays it:


#include "textformat.as"
_root.site.createEmptyMovieClip("blogPage", 2);
loadEntries = new LoadVars();
loadEntries.load("http://localhost/fblog/posts.php");
loadEntries.onLoad = function() {
	myIDs = new Array();
	myTitles = new Array();
	myDates = new Array();
	myContent = new Array();
	for (var a in this) {
		//this is where the magic needs to happen
		//but I have no idea what to do!
		if (a != "onLoad") {
			myIDs.push(this[a]);
			trace(myIDs);
		}
	}
	var e:Number = 0;
	for (e=0;e<myIDs.length;e++) {
		_root.site.blogPage.attachMovie("entry", "entry"+e, 50+e);
		_root.site.blogPage["entry"+e]._y = 150*e;
		_root.site.blogPage["entry"+e].dateText.text = myDates[e];
		_root.site.blogPage["entry"+e].contentText.text = myContent[e];
		_root.site.blogPage["entry"+e].titleText.text = myTitles[e];
		_root.site.blogPage["entry"+e].idText.text = myIDs[e];
	}
};

It’s very primitive at the moment.

Here’s my problem, I have no idea how to pull apart the string to get the right information in the right spots.

What I want to do is split the string into it’s elements (ie. id0, title0, date0, content0, id1, etc.) and once I’ve accomplished that, I want to sort out each ID into an array called myIDs, and each title into an array called myTitles, etc.

It’s been a long while since I’ve dealt with actionscript and I’ve never loaded data from a MySQL database for use in Flash before, so any comments are welcome on how to best accomplish this.

Thanks a lot,
Colin

Note to Mods: I put it in this forum because it really has very little to do with PHP and a lot to do with the Actionscript to get this working. If you feel this belongs somewhere better, go ahead and move it.

Solved:

Here’s the AS code that did the trick:


myIDs = new Array();
myTitles = new Array();
myDates = new Array();
myContent = new Array();
var arrayLength = this.length-1;
for (i=arrayLength; i>=0; i--) {
	myIDs.push(this["id"+i]);
	myTitles.push(this["title"+i]);
	myDates.push(this["date"+i]);
	myContent.push(this["content"+i]);
}

Basically what I did was made the PHP file output a length value (gotten from $num_rows):

print("&length=$num_rows");

which is used by the Flash movie to determine how many entries there are, and then it puts the specified values into the correct arrays using the FOR loop.