How Should you Include the XML Content in Flash?

There are several ways to include XML content within a Flash movie and all have different requirements. These options include:

  • The XML class

  • Data components

  • The XMLConnector or WebServiceConnector classes

  • The Web Service classes

  • The XMLSocket class

Ill look at each of these in turn .

Using the XML class

The XML class has been available within Flash since version 5, with only minor changes. You can use the XML class to load content from external XML documents into Flash. You can also modify XML data and send it from Flash for external updating with server-side files. If you want to work with the XML class, youll need to write ActionScript. You can find out more about the XML class in Chapter 4 of this book.

Using data components

Flash MX 2004 Professional and Flash Professional 8 include data components that provide a visual mechanism for working with XML documents. You can use the XMLConnector and WebServiceConnector components in your movies. You can drag components into your movie and configure them using the Component Inspector and Behaviors panel.

The data components allow you to bind XML content directly to user interface components. You can populate a ComboBox, List, or DataGrid component using the Component Inspector. You can also bind the content through a DataSet and XUpdateResolver component if you need to capture changes in your XML content. The XUpdateResolver can send changes to a server-side file for processing.

To learn more about the XMLConnector, DataSet, and XUpdateResolver components, see Chapter 8. Chapter 9 covers the WebServiceConnector component.

Using the XMLConnector, WebServiceConnector, and Web Service classes

The XMLConnector and WebServiceConnector classes are the script versions of the XMLConnector and WebServiceConnector data components. You can create and configure these components using ActionScript. This allows you to add the components to your movie entirely through code. You can even script the bindings to other UI components. You can find out more about scripting these components in chapters 8 and 9.

You can also script the Web Service classes to consume web services. This provides a little more control than youd get with the WebServiceConnector. Chapter 9 contains more information about these classes.

Using the XMLSocket class

The XMLSocket class allows you to remain connected to a socket server. The socket server can then push information into a Flash movie. This stops Flash from having to request information continually, as with the XML class. Chapter 10 covers the XMLSocket class.

Making the decision

With so many options available to you, it can be hard to decide on the appropriate method to use. The choice will depend on several factors:

  • Whether you need real-time or multiuser interaction

  • Whether the information is time sensitive

  • Which version of Flash you own

  • Which Flash players you are targeting

  • Whether you prefer to work visually or by writing ActionScript

In the next section, Ill cover each of these points. Ill finish by providing a diagram that summarizes these choices.

Do you need real-time interaction?

The first decision is whether you need to provide multiuser or real-time interaction with the XML data. Real-time interaction allows changes made outside of Flash to be fed into your application as they occur. Multiuser interaction enables you to work with multiple users and be notified immediately of changes that they make. In either case, you can achieve this functionality only by using a socket server and the XMLSocket class.

XMLSockets allow a socket server to push data into Flash. This is different from the request and response model of information gathering that Flash uses in the XML class and data components. Learn more about XMLSockets in Chapter 10.

Bear in mind that youre likely to require a financial investment in the socket server. You will also have to spend some time installing and configuring the server. If youre using a public web host, there may also be some issues with installing socket server software.

Is the information time sensitive?

Another reason for using the XMLSocket class with a socket server is if your information is time sensitive. Socket servers push information into Flash in real time so that the application always displays up-to-date data. You might need this functionality for a stock ticker or booking system that requires up-to-the-minute information.

If you dont need to use the XMLSocket class, there are some further decisions to consider when choosing between the XML class, the data components, and the Web Service classes.

Which version of Flash do you own?

You cant include XML content in a version of Flash prior to version 5. If you own either Flash MX 2004 Professional or Flash Professional 8, youll be able to use any of the methods listed earlier to include XML content. The Professional editions of Flash ship with data components and data-aware UI components that you can use to include XML content. You can either add these to your movie visually or script them.

If you own the basic version of Flash 8, you are limited to using the XML class to include XML content. Youll need to use ActionScript to include and manipulate XML content, and you can use either version 1.0 or version 2.0. The advantage in using version 2.0 is that you can enforce strict typing of variables . This helps you to avoid type mismatch errors and provides code hints.

Which Flash players are you targeting?

If youre targeting Flash players earlier than version 7, youll have to use the XML class. You have more choices if youre targeting Flash Player 7 and above. In this case, youll be able to use the data components or the XML class. You can work with the data components visually or by scripting them with ActionScript 2.0.

Do you prefer to work visually?

Your decision about including XML content also depends on how you prefer to work in Flash. Some people prefer to work visually, using the panels in Flash. Others prefer to write ActionScript to achieve the same functionality. If youre a visual developer who owns one of the Professional versions of Flash, youll probably prefer to use the data components. You can drag them onto the Stage and configure them using the Component Inspector. You can also create bindings using the Component Inspector.

Developers who are more comfortable working in code can achieve the same functionality by scripting the XML class or the data components. You can even script the Web Service classes if youre consuming web services. More experienced developers may wish to develop their own classes for working with XML content.

A decision diagram

Figure 11-1 shows a visual representation of the decision-making process that Ive just described. The diagram will help you to decide how best to include XML content in Flash.

image from book
Figure 11-1: The decision-making process


Foundation XML for Flash
Foundation XML for Flash
ISBN: 1590595432
EAN: 2147483647
Year: 2003
Pages: 93
Authors: Sas Jacobs

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net