The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.39 / 5.00 38,635 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.09 / 5.00 15,161 ViewsI'm not sure if this should be in the flash forums or not.. but it is related to php more, so I'm posting here.
I'm looking for a tutorial on php-actionscript(or mysql-actionscript) communication to make a browser game. I don't know if it's even possible.. but I'm looking anyways.
Any tuts people?
Or is it even possible to make php communicate with AS?
I'd assume that it's possible through XML. Flash has some ability to retrieve variables stored as HTML as far back as Flash MX 2004. I've never used the system, but if you make methods in your flash animation to interpret the xml and similarly in php, you'll be able to pull of what you want. I'm not sure how well it will work as far as timing, but you'll have to experiment to find out, or find someone who knows what they are talking about.
At 3/4/08 01:01 PM, DarkScythes wrote: Any tuts people?
Yea, there's a tutorial on this in AS:Main.
Lurk moar.
Technically this is a flash problem, and I hate developing in flash, but I figure I could share my experience on this problem.
Warning: This is stuff I've used to do a job with a pretty bloody tight deadline; I give no guarantees that this is the best way to go about doing this and I have no formal training in developing in flash. All my flash expertise is from trial and (lots of) error.
Anyway, loading an xml file is dead easy. Just go:
var xmlstuff:XML = new XML(); //Create a new XML object;
xmlstuff.onLoad = function(success)
{
//This function is called when the xml finishes loading, success is set to true if it's successful.
if (success){
play();
}
}
xmlstuff.ignorewhitespace = true; //Don't forget this! Your life will be hell without it
xmlstuff.load('loadnews.php'); //This can be any file at all provided it is (or outputs) valid xml
You can also use the getBytesLoaded and getBytesTotal methods on an xml object when you're loading it. This is pretty neat for preloaders.
Right for the following examples we're using the xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<news>
<article date="1204658399" poster="BoneIdol" title="example news article"><![CDATA[
Text of the article goes here
]]>
</article>
<article date="1204658299" poster="BoneIdol" title="example news article 2"><![CDATA[
Text of the article goes here
]]>
</article>
</news>
Once you have your xml loaded, we'll need to traverse through it to get any useful information out of it and into a format we can work with in flash. Let's start with traversing through our xml document. There's quite a few available and you should be able to look through the automatic code completion for them. It's pretty obvious what they do, just think of an xml document as being like a family tree. The 2 I found myself using most, however, are these 2:
xmlstuff.firstChild;
xmlstuff.childNode[0]; //This is an array
ChildNode is an array so you can do a .length and pass it through a loop to go through all the child elements in your xml node. Below is an example of how to loop through every <a rticle> and get useful data from it:
var newsArticles:XMLNode = xmlstuff.firstChild;
var numArticles:Number = newsArticles.length;
for (i = 0; i < numArticles; i++){
article = newsArticles[i];
txt = newsArticle.toString();
attrs = newsArticle.attributes; //This gets the attributes of an xml node in this case the title, poster and date
date = Number(attrs.date); //I've got stung here before, toString returns strings...
title = attrs.title;
poster = attrs.poster;
//Now do your thing, duplicate movie clips, fill out text boxes etc. etc.
}
Whenever you access an xml node, you generally get another xml node returned. Even if the node has no children, so you have to do .toString() to turn it into something you can work with. One of the downsides of this is that you will always get a string returned, which stung me really badly only a few days ago.
To access the attributes of an xml node, (title, date and posts for <a rticle>) just run the node through .attributes. Technically, this is supposed to return an array, but it actually returns an object. So you need to access your attributes by going xmlNode.attributes.attributeName; Bit of a pain really. You don't have to run these through .toString(), but they're returned as strings anyway, so be careful.
Once you have the xml data in a format you can work with in flash, you need to actually do something with it. I can't really offer a great deal of advice here besides that duplicateMovieClip() is your friend, and you'll probably be messing around with it for a while getting it to work, so get a fresh cup of tea or coffee before you get started.
Sorry if I didn't explain that too well, flash is not my strong suit and I don't understand actionscript in enough depth to really explain it well. Mostly, I'm just happy if I can get it working.
Sufficiently advanced incompetence is indistinguishable from malice.