Loading and Saving XML

This is a demo I created to demonstrate how to load and save data to an XML file. In the demo below you can add and remove balls as well as change their color. When you are finished you can click on “save” which saves your work into an XML file.

<?xml version="1.0" encoding="UTF-8"?>
<balllist>
<ball>

<id>0</id>
<x>80</x>
<y>50</y>
<c>0xFF0000</c>
<m>50</m>
</ball>
<ball>

<id>1</id>
<x>330</x>
<y>150</y>
<c>0x00FF00</c>
<m>100</m>
</ball>
<ball>

<id>2</id>
<x>450</x>
<y>70</y>
<c>0x0000FF</c>
<m>75</m>
</ball>
</balllist>

The XML file is then loaded using the following AS3 code. The data from the XML file is stored into an array “b” so that it can be easily accesssed and modified within the program.

var b : Array = new Array();
var loader : URLLoader = new URLLoader(); // used to load xml file
var xml : XML; // used to store XML data

loader.addEventListener(Event.COMPLETE, loadXML);
loader.load(new URLRequest("balls.xml"));

// gets executed when xml data has been loaded
function loadXML(e : Event) : void {

var i : int;
var n : int;

xml = new XML(e.target.data);
xml.ignoreWhitespace = true;
n = xml.ball.length(); // # of balls in XML file
// load xml data into ball array
for (i = 0; i < n; i++) {
b[i].x = xml.ball[i].x;
b[i].y = xml.ball[i].y;
b[i].c = xml.ball[i].c;
b[i].m = xml.ball[i].m;
}
}

To save the file, I just created a big string containing the XML code and sent it to a PHP routine via the “POST” method:

// saves the xml
function saveXML(e : Event) : void {

var s : String; // string containing XML
var h : String; // string to create a hexadecimal value for colours
var i : int;

// create xml as a string
s = '<balllist>n';
for (i = 0; i < b.length; i++) {
s = s + "t<ball>n";
s = s + "tt<id>" + i + "</id>n";
s = s + "tt<x>" + b[i].x + "</x>n";
s = s + "tt<y>" + b[i].y + "</y>n";
h = b[i].c.toString(16);
while (h.length < 6) {
h = "0" + h;
}
s = s + "tt<c>0x" + h + "</c>n";
s = s + "tt<m>" + b[i].m + "</m>n";
s = s + "t</ball>n";
}
s = s + "</balllist>";

// pass string to php routine which saves the data, using POST method
var req : URLRequest = new URLRequest();
var loader : URLLoader = new URLLoader();

req.data = s;
req.contentType = "text/xml";
req.method = URLRequestMethod.POST;
req.url = "SaveXML.php";
loader.load(req);
}

Finally I created a really simply PHP routine and saved it in a file called “SaveXML.php”. It simply dumps all of the text which was passed to it from Flash into the “balls.xml” file. Here is the code:

<?php

// simple routine to save xml file
// passed a large string from flash using post method

if (isset($GLOBALS["HTTP_RAW_POST_DATA"])) {
$xml = $GLOBALS["HTTP_RAW_POST_DATA"];
$file = fopen("balls.xml","wb");
fwrite($file, $xml);
fclose($file);
}

?>

Open letter to @Adobe & Adobe AIR

This letter was written by Gary Paluk:

Re: http://blogs.adobe.com/digitalmarketing/web-experience/adobe-experience-manager-mobile-app-announcement/

The following message was originally posted on facebook:
https://www.facebook.com/garypaluk/posts/10152028727336149

Hi Loni, firstly, thank you for your response to questions. I was a developer of the Away3D TypeScript HTML5 project which was funded by Adobe. I wrote my own Flash/Air 3D engine called Zest3D which had no funding from Adobe, so I’m in quite a good position to comment given my experience with the technologies being discussed.

The comments here illustrate just how concerned developers are, developers that have invested in Adobe technology over the years. I have invested 13 years of my own development career in Adobe products and evangelized the technology over that time. Your users can see that there is a perfectly good technology that does more than the new HTML5 offerings and they are evidently frustrated that you are not supporting developers that do not see why they aught to retrain to use an inferior technology.

Whilst I understand business choices are being made to support HTML5, Adobe should understand developers will leave rather than use inferior technology. I, for one, would resent moving to your HTML5 technology and every highly skilled developer that I have spoken to has said the same. You can see that in the comments already received.

Many of those developers feel that Adobes evangelist attitude to HTML5 is misplaced and a PR/market bending directive that is damaging their livelihoods and the skill-sets that they have accumulated and as most people would understand, developers and artists want to use the best products and workflows to get a job complete. In this case, the best product is Adobe Air and certainly not PhoneGap. So why do we keep seeing Adobe pushing the technologies that the developers do not want?

I would like to take the opportunity to ask Adobe to speak out and offer their support to existing developers with serious PR and coverage and continued accelerated roadmap for the Adobe Flash and Air product before all of your best developers leave and take their years of development and programming skills with them. Adobe has seen this already as developers have sought to find other native solutions, Unitiy has become the entry level tool of choice and companies like myself and Minko are essentially planning or working on building superior tools that may soon make Air obsolete whilst supporting native and HTML5 development without the need for an Adobe toolchain. This is the effect of alienating your development community and losing sales of your supporting tools.

Personally, I do not want to see Adobe Air or Adobe Flash disappear as they both have a formidable user base, excellent workflow, perfect cross-platform capability. With a small amount of investment, I feel that Flash and Air could be a much superior technology and with this approach Adobe might regain the trust of their developer community whilst continuing to enrich the lives of those developers who have continued to champion Adobes history of excellent web technologies.

Gary Paluk
http://www.plugin.io