Home arrow Flash arrow Page 6 - Working with external data in Flash
FLASH

Working with external data in Flash


Because data for a website comes in many formats, it helps to have a variety of ways to handle this data. This article covers the different methods available in ActionScript for exchanging data.

Author Info:
By: Adi Reddy Mora
Rating: 4 stars4 stars4 stars4 stars4 stars / 26
May 11, 2005
TABLE OF CONTENTS:
  1. · Working with external data in Flash
  2. · getURL(), loadVariables(),loadVariablesNum(), loadMovie(), and loadMovieNum() methods
  3. · LoadVars Class
  4. · MovieClipLoader class
  5. · XML Class
  6. · XMLSocket Class

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Working with external data in Flash - XMLSocket Class
(Page 6 of 6 )

XMLSocket class in ActionScript lets you open a continuous connection with a server. A socket connection lets the server publish, or  push, information to the client as soon as that information is available. The data is sent over the socket connection as one string and should be formatted as XML. You can use the XML class to structure the data.

The methods of XMLSocket Class create and use TCP/IP socket connections to send and load information as XML.

You can use the connect()and send()methods of the XMLSocket class to transfer XML to and from a server over a socket connection. The connect()method establishes a socket connection with a Web server port. The send()method passes an XML object to the server specified in the socket connection.

Now let us see an example that shows how to use the XMLSocket Class.

Example:

// Create XMLSocket object
var sample_socket:XMLSocket = new XMLSocket();
// Connects to localhost server with port number 1024
sample_socket.connect("localhost", 1024);
// Displays connection status information
sample_socket.onConnect = function(status) {
 if (status) {
   conn_txt.text = "connection successful";
 } else {
   conn_txt.text = "no connection made";
 }
};
// Function that creates data to send it to the server using

send() method
function sendData() {
 var data:XML = new XML();
 var send = data.createElement("user");
 send.attributes.id = "asp123";
 data.appendChild(send);
 sample_socket.send(data);
}
// onData event handler function to track the data returned from

socket connection and perform actions based on that data
sample_socket.onData = function(msg:String):Void {
 trace(msg);

};

Note:The XMLSocket.connect()method can connect only to TCP port numbers greater than or equal to 1024. Port numbers below 1024 are often used by system services such as FTP, Telnet, and HTTP, so XMLSocket objects are barred from these ports for security reasons.


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
FLASH ARTICLES

- More Top Flash Game Tutorials
- Top Flash Game Tutorials
- Best Flash Photo Gallery Tutorials
- The Top Flash Tutorials for Menus
- 7 Great Flash Tutorials
- Adobe Creative Suite 5.5 Now Available
- Critical Flash Vulnerability Heats Up the Web
- More on Nonpersistent Client-Side Remote Sha...
- Nonpersistent Client-Side Remote Shared Obje...
- Using the Decorator Pattern for a Real Web S...
- Using Concrete Decorator Classes
- Delving More Deeply into the Decorator Patte...
- The Decorator Pattern in Action
- A Simple Decorator Pattern Example
- Decorator Pattern

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials