ActionScript 3.0 introduces a number of formidable tools of communication, some totally new, some revised and improved from previous versions 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 the XML response. First of all, the object XML does not exist anymore! ActionScript 3.0 introduced new classes have been, some of which are dedicated to the "backward compatibility".
Note: The XML class (along with related classes) from ActionScript 2.0 have been renamed XMLDocument and moved to the flash.xml package. It is included in ActionScript 3.0 to ensure compatibility with previous versions.
usando il metodo sendAndLoad() dell'oggetto LoadVars (vedi: Flash: LoadVars e XML per inviare dati in POST ). In ActionScript 2.0 communication with a Web Server was often solved 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 indicated in the manual, in fact:
The XMLDocument class represents the legacy XML object that was present 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 well as XMLNode and XMLNodeType, is present for backward compatibility. The functionality for loading XML documents is now provided by the URLLoader class.
ActionScript 3.0 improves things, even if at first sight of the classes involved are more numerous than before. , URLLoader e XML. In our particular case we're going to use the objects are: URLVariables , URLRequest , URLLoader , and XML.
Here is an example of sending and receiving:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | URLVariables = new URLVariables ( ) ; var variables: URLVariables = new URLVariables (); ; variables. MyVar = "Hello"; URLRequest = new URLRequest ( ) ; var request: URLRequest = new URLRequest (); = "http://www.miodominio.com/miapagina.php" ; request. url = "http://www.miodominio.com/miapagina.php"; = URLRequestMethod . POST ; request. method = URLRequestMethod . POST; = variables ; request. data = variables; : URLLoader = new URLLoader ( ) ; var loader: URLLoader = new URLLoader (); dataFormat = URLLoaderDataFormat . TEXT ; loader. dataFormat = URLLoaderDataFormat . TEXT; addEventListener ( Event . COMPLETE , completeHandler ) ; loader. addEventListener ( Event . COMPLETE completeHandler); try { load ( request ) ; loader. load (request); ( error : Error ) { } Catch (error: Error ) { "Errore nel caricamento dell' URL" ) ; trace ("Error loading of 'URL'); } event : Event ) : void { completeHandler function (event: Event ): void { XML = XML ( event . target . data ) ; var x_xml: XML = XML (event. target. date); x_xml ) ; trace (x_xml); } |
The server (miapagina.php), of course, does not change. . Compared to the example shown in Flash: LoadVars and XML to send data in POST we note that the object LoadVars ActionScript 2.0 was used both as a vehicle and as a subject of the POST variables sent, through his method sendAndLoad() . per l'invio. In ActionScript 3.0, these two functions are carried out by two separate objects: URLVariables as a vehicle of the variables (POST or GET) and URLLoader to send. The separation, of course, improves the previous situation provides us with two objects as "dedicated" that, among other things, play several important (and innovative) additional tasks - as we will see in the future.
On this topic (extremely large in ActionScript 3.0) we will return later analyzing also present in other big news items for the communication and connection with the Web Server.











There are no comments for this post
Leave a comment