Categories

Partners
  • Website Templates

  • Design Feeds

  • Adobe Photoshop Tutorials

  • Website Templates, WordPress Themes

  • Website Templates

  • Flash Web Sites

  • Photoshop Templates

  • Photo Contests

  • Photo Tips
  • Search


    Advanced Search


    Partner Links
  • Adobe Photoshop Tutorials

  • Free Stock Photos and Images



  • Website Templates

    Creating an XML Packet with Flash - the hard way
    Published  06/19/2006 | Macromedia Flash
       




    Creating an XML Packet with Flash (the hard way)

    One way of building XML packets from scratch using ActionScript is to use the createElement method to make the new XML node and then populate the packet by directly setting attributes and values, as shown below:

    1. var submitListener:Object = new Object();

    2. submitListener.click = function() {

    3.     var login_xml:XML = new XML();

    4.     login_xml.xmlDecl = "<?xml version=\"1.0\" ?>";

    5.     var loginElement:XMLNode = login_xml.createElement("login");

    6.     loginElement.attributes.username = username_txt.text;

    7.     loginElement.attributes.password = password_txt.text;

    8.     login_xml.appendChild(loginElement);

    9.     packet_txt.text = login_xml;

    10. };

    11. submit_btn.addEventListener("click", submitListener);

     

    But before you can test this code you need to add a few components to your Stage. First, drag two TextInput components on to your Stage and give them the instance names "username_txt" and "password_txt". Next we need to add a Button component with the instance name submit_btn. Finally add a TextArea component and assign it an instance name of packet_txt. You may want to resize the components and add any appropriate labels or static text to the Flash document to make it a bit more user friendly, you can use the SWF file below as a general guide.

    Once you've added the required components and given them the proper instance names, you are free to test the movie. Enter a value in both the username and password field and click the submit button. The Flash document will create a new XML packet on the fly, append the values of username_txt and password_txt, set the appropriate XML declaration and display the final packet in the giant text area.

    Article Series
    This article is part 4 of a 13 part series. Other articles in this series are shown below:
    1. Flash FAQ - Introduction
    2. Streaming FLV files in Flash MX 2004
    3. Creating an XML Packet with Flash - the easy way
    4. Creating an XML Packet with Flash - the hard way
    5. Getting more colors for your Halo
    6. Loading in Images Using the MovieClipLoader Class
    7. Parsing an XML Packet in Flash
    8. Parsing XML in Flash Using the XMLConnector
    9. Sending an XML Packet to a Server-Side Page
    10. Using LoadVars.send Method to Exchange Data with a Server-Side Script
    11. Using the Alert component
    12. Using the LoadVars Class to Load Variables
    13. Using XPath in Flash MX 2004