Flash CS3: communicating with a Web Server
Friday, December 14, 2007 ActionScript 3.0 introduces a number of formidable instruments of communication, some totally new, others revised and improved from the previous version of ActionScript. We begin to see how it changes the way you interact with a Web Server in the case of a simple communication between Flash and a PHP page with a response in XML. First, the object XML is no more! ActionScript 3.0 introduced new classes have been, some of which are dedicated to the "backwards".
Note: The XML class (along with related classes) from ActionScript 2.0 has been renamed XMLDocument and moved into flash.xml package. It is included in ActionScript 3.0 to ensure compatibility with older versions.
In ActionScript 2.0 communication with a Web server was often resolved by using the combination of objects LoadVars and XML, using the method sendAndLoad() object LoadVars (see: Flash: LoadVars and XML to send data in POST). Now things are changing, but you just get used to new names and objects. As stated in the manual, in fact:
The XMLDocument class represents the XML object that was present earlier in ActionScript 2.0. The name was changed in ActionScript 3.0 to XMLDocument to avoid name conflicts with the new XML class in ActionScript 3.0. In ActionScript 3.0, you should use the new XML class and related classes, which support E4X (ECMAScript for XML).
The XMLDocument class, as XMLNode and XmlNodeType, is present to ensure backward compatibility. The functionality of loading of XML documents is now provided by the URLLoader class.
ActionScript 3.0 improves things, even if at first glance the classes involved are more numerous than before. In our case, in particular objects that we are going to use are: URLVariables URLRequest URLLoader and XML.
Here is an example of sending and receiving:
- ; variables. MyVar = "Hello";
- = "http://www.miodominio.com/miapagina.php" ; request. url = "http://www.miodominio.com/miapagina.php";
- = variables ; request. data = variables;
- try (
- load ( request ) ; loader. load (request);
- "Errore nel caricamento dell' URL" ) ; trace ( "Error Loading 'URL');
- )
- x_xml ) ; trace (x_xml);
- )
The server side (miapagina.php), of course, does not change. Compared to the example shown in Flash: LoadVars and XML to send data in POST, we notice that the object LoadVars in ActionScript 2.0 was used both as a vehicle of POST variables and as being sent through his method sendAndLoad() In ActionScript 3.0, these two functions are performed by two separate objects: URLVariables as a vehicle of variables (POST or GET) and URLLoader to send. The separation, of course, improve the previous situation, since it provides two things "devoted" which, among other things, play many important (and innovative) additional tasks - as we shall see in the future.
On this subject (extremely broad in ActionScript 3.0) return later analysis also found in other big news items for the communication and connection with the Web Server.













There are no comments for this post
Leave a comment