0%

Book Description

XML is the lingua franca of the Web. All designers and developers working in a web environment need a sound understanding of XML and its role in application development. Many software packages and organizations allow for the exchange of data using an XML format. Web services and RSS feeds are now commonplace.

For those working with Flash and Flex, a thorough understanding of XML is particularly important. XML documents are one option for the data provided to SWF applications. Flash and Flex can load, display, and modify XML content. These applications can also send XML content to other applications for updating or for use in different situations.

ActionScript 3.0 introduced some fundamental changes to the way in which Flash and Flex applications work with XML. One significant change is that XML is now a native data type. ActionScript 3.0 also introduced new classes and a different framework for working with external documents. These changes are based on the E4X ECMAScript standard, and they streamline and simplify the process for working with XML in Flash and Flex.

In Foundation XML and E4X for Flash and Flex, Sas Jacobs gives you an introduction to XML and E4X. She explores the XML and XMLList classes and explains E4X expressions, providing examples for both Flash and Flex. In addition to explaining how to incorporate XML documents in Shockwave Flash applications, Sas shows you approaches specific to Flash and Flex and explores real-world usage. The book finishes with two case studies. In the first, you will learn how to consume and display information and images from Flickr using Flash. In the second, you will work with Adobe Kuler in Flex.

Whether you are a designer or developer, this book will help you work with XML and make the transition from ActionScript 2.0 to ActionScript 3.0. It will also provide you with an excellent grounding if you are new to Flash and Flex.

Table of Contents

  1. Copyright
  2. ABOUT THE AUTHOR
  3. ABOUT THE TECHNICAL REVIEWER
  4. ABOUT THE COVER IMAGE DESIGNER
  5. ACKNOWLEDGMENTS
  6. INTRODUCTION
  7. 1. INTRODUCTION TO XML
    1. 1.1. What is XML?
      1. 1.1.1. Understanding XML
      2. 1.1.2. Storing information in XML documents
      3. 1.1.3. XML, in the beginning
      4. 1.1.4. An XML example
    2. 1.2. Why XML?
      1. 1.2.1. Simple
      2. 1.2.2. Flexible
      3. 1.2.3. Descriptive
      4. 1.2.4. Accessible
      5. 1.2.5. Independent
      6. 1.2.6. Precise
      7. 1.2.7. Free
    3. 1.3. Why is XML important in Flash and Flex?
      1. 1.3.1. XML as a SWF data source
      2. 1.3.2. MXML in Flex
      3. 1.3.3. ActionScript 3.0 and XML
    4. 1.4. XML document sections
      1. 1.4.1. Document prolog
        1. 1.4.1.1. XML declaration
        2. 1.4.1.2. Processing instructions
        3. 1.4.1.3. Document Type Definitions
      2. 1.4.2. Document tree
      3. 1.4.3. Whitespace
      4. 1.4.4. Namespaces
    5. 1.5. Structuring XML documents
      1. 1.5.1. Elements
        1. 1.5.1.1. Writing elements
        2. 1.5.1.2. Naming elements
        3. 1.5.1.3. Populating elements
        4. 1.5.1.4. The first element
      2. 1.5.2. Attributes
        1. 1.5.2.1. Writing attributes
        2. 1.5.2.2. Naming attributes
        3. 1.5.2.3. Structuring attributes as elements
      3. 1.5.3. Text
      4. 1.5.4. Entities
      5. 1.5.5. Comments
      6. 1.5.6. CDATA
    6. 1.6. A simple XML document
    7. 1.7. Understanding well-formed documents
      1. 1.7.1. Element structure
      2. 1.7.2. Element nesting
      3. 1.7.3. Element closing
      4. 1.7.4. Element opening and closing tags
      5. 1.7.5. Quotes for attributes
      6. 1.7.6. Documents that aren't well-formed
    8. 1.8. XML, HTML, and XHTML
      1. 1.8.1. Understanding HTML
      2. 1.8.2. How is XML different from HTML?
      3. 1.8.3. Where does XHTML fit in?
    9. 1.9. Understanding related recommendations
      1. 1.9.1. Understanding DTDs and XML schemas
      2. 1.9.2. Understanding XSL
    10. 1.10. Summary
  8. 2. GENERATING XML CONTENT
    1. 2.1. Authoring XML documents in a text editor
      1. 2.1.1. Using text and HTML editors
      2. 2.1.2. Using XML editors
        1. 2.1.2.1. Using Stylus Studio 2008 XML
        2. 2.1.2.2. Working with Dreamweaver
    2. 2.2. Generating XML content from a database
      1. 2.2.1. Using a web server to generate XML content
      2. 2.2.2. Working with VB .NET
      3. 2.2.3. Working with PHP
      4. 2.2.4. Working with ColdFusion
    3. 2.3. Generating XML from other software packages
      1. 2.3.1. Getting started with XML in Excel 2007 and Word 2007
      2. 2.3.2. Generating XML from Word 2007
        1. 2.3.2.1. Creating an XML document in Word using Save As
        2. 2.3.2.2. Creating XML content in Word by using a schema
      3. 2.3.3. Generating XML from Excel 2007
        1. 2.3.3.1. Generating an XML document in Excel using Save As
        2. 2.3.3.2. Creating XML content in Excel using a schema
      4. 2.3.4. Creating XML content with Access 2007
    4. 2.4. Validation and XML content in SWF applications
    5. 2.5. Summary
  9. 3. ACTIONSCRIPT 3.0 AND XML
    1. 3.1. Differences between ActionScript 2.0 and 3.0
    2. 3.2. XML as an ActionScript data type
      1. 3.2.1. Writing XML inline within ActionScript
      2. 3.2.2. Writing XML with the XML tag in Flex
    3. 3.3. Overview of the new ActionScript 3.0 classes
      1. 3.3.1. The ActionScript 3.0 XML class
      2. 3.3.2. The XMLList class
      3. 3.3.3. The XMLListCollection class
      4. 3.3.4. The QName and Namespace classes
    4. 3.4. Working with the XML class
      1. 3.4.1. Properties of the XML class
        1. 3.4.1.1. Working with XML properties in Flash
        2. 3.4.1.2. Working with XML properties in Flex
      2. 3.4.2. Methods of the XML class
      3. 3.4.3. Locating XML content
        1. 3.4.3.1. Instructions for the code samples
        2. 3.4.3.2. Working with attribute() and attributes()
        3. 3.4.3.3. Finding child elements
        4. 3.4.3.4. Finding descendants
        5. 3.4.3.5. Finding elements
        6. 3.4.3.6. Finding the parent element
        7. 3.4.3.7. Locating text
      4. 3.4.4. Finding information about XML content
        1. 3.4.4.1. Finding an object's position within its parent
        2. 3.4.4.2. Determining content type
        3. 3.4.4.3. Determining the number of elements
        4. 3.4.4.4. Displaying the name of an element
        5. 3.4.4.5. Determining the type of node
        6. 3.4.4.6. Displaying a string representation of XML
      5. 3.4.5. Modifying XML content
    5. 3.5. Working with the XMLList class
    6. 3.6. Working with the XMLListCollection class in Flex
      1. 3.6.1. Setting up the Flex application
      2. 3.6.2. Using a function to filter an XMLListCollection
      3. 3.6.3. Sorting an XMLListCollection
    7. 3.7. Understanding the Namespace class
    8. 3.8. Understanding the QName class
    9. 3.9. Limitations of working with the XML class
    10. 3.10. Summary
  10. 4. USING E4X EXPRESSIONS
    1. 4.1. Understanding E4X expressions
      1. 4.1.1. Working through the examples
        1. 4.1.1.1. Working with Flash
        2. 4.1.1.2. Working with Flex
      2. 4.1.2. Using the dot operator to specify a path
        1. 4.1.2.1. Returning text
        2. 4.1.2.2. Returning an XMLList
        3. 4.1.2.3. Specifying an index
        4. 4.1.2.4. Finding the last element
        5. 4.1.2.5. Casting returned content
        6. 4.1.2.6. Using the wildcard operator (*)
      3. 4.1.3. Using the attribute operator (@)
      4. 4.1.4. Looping through attributes
      5. 4.1.5. Using the descendants operator (..)
    2. 4.2. Working with filter expressions
      1. 4.2.1. Working with equality
      2. 4.2.2. Finding inequality
      3. 4.2.3. Other comparisons
      4. 4.2.4. Using AND and OR in conditions
      5. 4.2.5. Using the additive operator (+)
      6. 4.2.6. Including other ActionScript expressions
    3. 4.3. Assigning values
      1. 4.3.1. Simple assignment with =
      2. 4.3.2. Compound assignment with +=
    4. 4.4. Deleting content
    5. 4.5. E4X in action
      1. 4.5.1. Flash example
      2. 4.5.2. Flex example
    6. 4.6. Summary
  11. 5. USING THE URLLOADER CLASS WITH XML DOCUMENTS
    1. 5.1. Using the URLLoader class
      1. 5.1.1. Properties of the URLLoader class
      2. 5.1.2. Methods of the URLLoader class
      3. 5.1.3. Events of the URLLoader class
      4. 5.1.4. Limits of the URLLoader class
    2. 5.2. Putting it all together
      1. 5.2.1. Creating a URLLoader object
      2. 5.2.2. Making the request
      3. 5.2.3. Sending variables with the request
      4. 5.2.4. Tracking the progress of a request
      5. 5.2.5. Receiving a response
      6. 5.2.6. Detecting errors
      7. 5.2.7. Working through examples
        1. 5.2.7.1. Working in Flash
        2. 5.2.7.2. Working in Flex
    3. 5.3. Updating content with the URLLoader class
      1. 5.3.1. Sending variables in a Flash application
      2. 5.3.2. Sending variables in a Flex application
    4. 5.4. Understanding Flash Player security
      1. 5.4.1. Understanding security sandboxes
      2. 5.4.2. Creating a cross-domain policy file
        1. 5.4.2.1. Writing a cross-domain policy file
        2. 5.4.2.2. Issues with the cross-domain policy file
      3. 5.4.3. Proxying data locally
    5. 5.5. Summary
  12. 6. LOADING METHODS SPECIFIC TO FLEX
    1. 6.1. Loading external content
    2. 6.2. Using the <mx:HTTPService> tag
      1. 6.2.1. Properties of the <mx:HTTPService> tag
      2. 6.2.2. Methods of the <mx:HTTPService> tag
      3. 6.2.3. Events of the <mx:HTTPService> tag
      4. 6.2.4. Putting it all together
        1. 6.2.4.1. Creating an HTTPService request
        2. 6.2.4.2. Making the request
        3. 6.2.4.3. Sending variables with the request
        4. 6.2.4.4. Specifying a return type
        5. 6.2.4.5. Specifying a request method
        6. 6.2.4.6. Receiving a response
    3. 6.3. Using the HTTPService class
      1. 6.3.1. Properties, methods, and events of the HTTPService class
      2. 6.3.2. Putting it all together
        1. 6.3.2.1. Creating an HTTPService request
        2. 6.3.2.2. Making the request
        3. 6.3.2.3. Sending variables with the request
        4. 6.3.2.4. Specifying a return type
        5. 6.3.2.5. Specifying a request method
        6. 6.3.2.6. Receiving a response
    4. 6.4. Accessing loaded content
      1. 6.4.1. Accessing the lastResult property directly
      2. 6.4.2. Binding the lastResult property
    5. 6.5. Working through an <mx:HTTPService> tag example
    6. 6.6. Working through an HTTPService class example
    7. 6.7. Passing variables with the request
      1. 6.7.1. Using <mx:request> to send variables
      2. 6.7.2. Sending variables with the HTTPService class
    8. 6.8. Summary
  13. 7. LOADING METHODS SPECIFIC TO FLASH
    1. 7.1. Understanding the AS 2.0 data components
    2. 7.2. Understanding the XMLConnector
      1. 7.2.1. Displaying read-only XML content
      2. 7.2.2. Displaying updatable XML data
    3. 7.3. Configuring the XMLConnector
      1. 7.3.1. Using the Component Inspector
        1. 7.3.1.1. Creating a schema from an XML document
        2. 7.3.1.2. Creating a schema by adding fields
        3. 7.3.1.3. Understanding schema settings
      2. 7.3.2. Triggering the XMLConnector component
      3. 7.3.3. Testing for a loaded XML document
      4. 7.3.4. Working through a loading example
    4. 7.4. Binding XML data directly to UI components
      1. 7.4.1. Adding a binding
      2. 7.4.2. Configuring the binding
        1. 7.4.2.1. Working through a binding example
        2. 7.4.2.2. Extending the binding example
    5. 7.5. Using the DataSet component
      1. 7.5.1. Creating bindings with a DataSet component
      2. 7.5.2. Putting it all together
    6. 7.6. Summary
  14. 8. MODIFYING XML CONTENT WITH ACTIONSCRIPT 3.0
    1. 8.1. Setting up the examples
      1. 8.1.1. Setting up the Flash examples
      2. 8.1.2. Setting up the Flex examples
    2. 8.2. Changing element and attribute values
    3. 8.3. Adding, editing, and deleting XML content
      1. 8.3.1. Using appendChild()
      2. 8.3.2. Using prependChild()
      3. 8.3.3. Copying a node
      4. 8.3.4. Inserting a child node
      5. 8.3.5. Editing content
      6. 8.3.6. Using setChildren()
      7. 8.3.7. Deleting an element
    4. 8.4. Modifying element names and namespaces
      1. 8.4.1. Adding a namespace
      2. 8.4.2. Removing a namespace
      3. 8.4.3. Setting the namespace
      4. 8.4.4. Changing the local element name
      5. 8.4.5. Changing the qualified element name
    5. 8.5. Working through a modification example
      1. 8.5.1. Working in Flash
      2. 8.5.2. Working in Flex
      3. 8.5.3. Points to note about the example
    6. 8.6. Summary
  15. 9. COMMUNICATING WITH THE SERVER
    1. 9.1. Sending data to the server
      1. 9.1.1. Structuring the file path
      2. 9.1.2. Sending the variables
        1. 9.1.2.1. Choosing a method
        2. 9.1.2.2. Choosing the format
    2. 9.2. Working with the URLLoader class
      1. 9.2.1. Sending variables with the URLLoader class
      2. 9.2.2. Receiving a response
      3. 9.2.3. Handling errors
      4. 9.2.4. Working through a URLLoader class example
        1. 9.2.4.1. Understanding the VB .NET page
        2. 9.2.4.2. Understanding the PHP page
        3. 9.2.4.3. Understanding the ColdFusion page
        4. 9.2.4.4. Working through the Flash example
        5. 9.2.4.5. Working through the Flex example
        6. 9.2.4.6. Working with the <mx:HTTPService> element
    3. 9.3. Sending variables with the <mx:HTTPService> element
      1. 9.3.1. Receiving a response
      2. 9.3.2. Handling errors
      3. 9.3.3. Working through an <mx:HTTPService> element example
    4. 9.4. Working with the HTTPService class in Flex
      1. 9.4.1. Sending variables with the HTTPService class
      2. 9.4.2. Receiving a response
      3. 9.4.3. Handling errors
      4. 9.4.4. Working through a HTTPService class example
    5. 9.5. Choosing the Flex approach
    6. 9.6. Summary
  16. 10. CONSUMING WEB SERVICES WITH FLEX
    1. 10.1. Understanding web services
      1. 10.1.1. Understanding SOAP web services
      2. 10.1.2. Understanding the role of WSDL
    2. 10.2. Using Flex to consume a web service
    3. 10.3. Working with the <mx:WebService> element
      1. 10.3.1. Creating the web service request
      2. 10.3.2. Specifying the operation
      3. 10.3.3. Making the request
      4. 10.3.4. Receiving the response
      5. 10.3.5. Accessing the reply
      6. 10.3.6. Understanding the resultFormat of an operation
      7. 10.3.7. Handling errors
      8. 10.3.8. Working through a tag-based example
    4. 10.4. Working with the WebService class
      1. 10.4.1. Properties of the WebService class
      2. 10.4.2. Methods of the WebService class
      3. 10.4.3. Events of the WebService class
      4. 10.4.4. Understanding the Operation class
      5. 10.4.5. Properties of the Operation class
      6. 10.4.6. Methods of the Operation class
      7. 10.4.7. Events of the Operation class
    5. 10.5. Consuming a web service with ActionScript
      1. 10.5.1. Creating the web service request
      2. 10.5.2. Specifying the operation
      3. 10.5.3. Making the request
      4. 10.5.4. Receiving the response
      5. 10.5.5. Accessing the reply
      6. 10.5.6. Understanding returned data types
      7. 10.5.7. Handling errors
      8. 10.5.8. Working through a scripted example
    6. 10.6. Using Flex Builder to manage web services
      1. 10.6.1. Working through the Web Service Introspection wizard
      2. 10.6.2. Managing web services
      3. 10.6.3. Consuming the web service
        1. 10.6.3.1. Using MXML tags with the generated classes
        2. 10.6.3.2. Scripting the generated classes
    7. 10.7. Summary
  17. 11. CONSUMING WEB SERVICES WITH FLASH
    1. 11.1. Consuming web services with the URLLoader class
      1. 11.1.1. Understanding the WSDL file
      2. 11.1.2. Using GET to consume a web service
        1. 11.1.2.1. Working through a GET example
      3. 11.1.3. Consuming a web service with POST
        1. 11.1.3.1. Working through a POST example
      4. 11.1.4. Consuming a SOAP web service with the as3webservice extension
        1. 11.1.4.1. Working through an as3webservice example
    2. 11.2. Consuming a SOAP web service with the WebServiceConnector component
      1. 11.2.1. Configuring the WebServiceConnector
        1. 11.2.1.1. Adding parameters
        2. 11.2.1.2. Determining the arguments for the operation
        3. 11.2.1.3. Adding parameter bindings
        4. 11.2.1.4. Triggering the web services call
        5. 11.2.1.5. Binding the results
        6. 11.2.1.6. Accessing the results in ActionScript
      2. 11.2.2. Viewing the Web Services panel
      3. 11.2.3. Working through a WebServiceConnector example
    3. 11.3. Summary
  18. 12. FLASH CASE STUDY
    1. 12.1. Understanding Flickr
      1. 12.1.1. Applying for a Flickr key
      2. 12.1.2. Making a Flickr request
      3. 12.1.3. Understanding the Flickr API
        1. 12.1.3.1. Understanding the returned photo XML document
        2. 12.1.3.2. Understanding the returned people XML document
        3. 12.1.3.3. Finding recent photos
        4. 12.1.3.4. Finding interesting photos
        5. 12.1.3.5. Searching for photos
        6. 12.1.3.6. Finding owner information
      4. 12.1.4. Receiving a Flickr response
        1. 12.1.4.1. Receiving photo information
        2. 12.1.4.2. Receiving person information
        3. 12.1.4.3. Finding the URL of a photo
        4. 12.1.4.4. Finding the page containing the photo
    2. 12.2. Building the application
      1. 12.2.1. Working through the interface
      2. 12.2.2. Setting up the application
      3. 12.2.3. Getting the recent photos list
      4. 12.2.4. Displaying a large image and title
      5. 12.2.5. Adding paging functionality
      6. 12.2.6. Making cosmetic changes to the interface
      7. 12.2.7. Viewing interesting photos
      8. 12.2.8. Searching Flickr
      9. 12.2.9. Showing owner information
    3. 12.3. Summary
  19. 13. FLEX CASE STUDY
    1. 13.1. Understanding Adobe Kuler
      1. 13.1.1. Applying for a Kuler key
      2. 13.1.2. Understanding the Kuler feeds
        1. 13.1.2.1. Accessing an existing feed
        2. 13.1.2.2. Searching Kuler
      3. 13.1.3. Receiving a Kuler response
    2. 13.2. Building the application
      1. 13.2.1. Working through the interface
      2. 13.2.2. Setting up the application
      3. 13.2.3. Creating the custom class file
      4. 13.2.4. Getting the highest rated themes
      5. 13.2.5. Displaying the theme
      6. 13.2.6. Adding paging functionality
      7. 13.2.7. Displaying the most popular schemes
      8. 13.2.8. Searching Kuler
      9. 13.2.9. Reviewing the completed code
        1. 13.2.9.1. KulerLoader.as
        2. 13.2.9.2. ColorSwatch.mxml
        3. 13.2.9.3. KulerCompleted.mxml
    3. 13.3. Summary
18.221.85.33