Wednesday, June 09, 2004 - Posts

Flash and XML

Hey all I have a project that maybe will use PHP,Mysql but they aren't sure yet if they want to use Flash or HTML and because I'm young and very impatient i allready wanted to start so what is the way to do??? let PHP give some XML :)

So here is just a small actionscripting that may help.

Make XML in Flash:
/* Make XML in Flash */
//Create XML object

xmlSend = new XML();
//Create a Tag
info = xmlSend.createElement("info");
//Create a other Tag
user = xmlSend.createElement("user");
 //Give the other Tag some info
 user.attributes.name = "warstar";
//Put the other tag into the Tag
info.appendChild(user);
//Put the other tag into the Tag
xmlSend.appendChild(info);
/* End Make XML in Flash */
Now xmlSend will be: <info><user name="warstar" /></info>

Now for getting some info from XML into Flash that will go like this:
/* Load and process XML */
//Create XML object

xmlGet = new XML();
//Set object to ignore White spaces
xmlGet.ignoreWhite = true;
//Load informtion from info.xml
xmlGet.load("info.xml");
//Set that if data is loaded goto function myOnLoad
xmlGet.onLoad = myOnLoad;
//Function myOnLoad
function myOnLoad(succes)
{
 //Check if all went well
 if(succes)
 {
  //Get the first Node
  rootNode = xmlGet.firstChild;
    
  //Get the firstNode in the node
  currentNode = rootNode.firstChild;
  //Brows to all the nodes
  while(currentNode!= null)
  {
   //Put the information into variable txt
   txt += currentNode.attributes.id + " - ";
   //Goto next node
   currentNode = currentNode.nextSibling;
  }
 }
}
/* Load and process XML */
The XML file looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<info>
  
<user id="1" name="warstar" pass="****" />
</info>

Sorry i'm not explaining mutch but i'm really Tired So

happy Neeting, let the bed bugs bite