Is XML the Best Choice?

To start with, youll need to consider whether XML is the best choice for your data. By definition, XML is a verbose way to store information; it requires a text-based tag structure to be included in addition to the data. XML documents are likely to take up more space compared with their text file counterparts, which means choosing XML as a data storage medium could affect the size and speed of your application. Its obviously going to be quicker to load a smaller file into Flash. It will also be quicker to extract the information from a smaller file.

For very large amounts of data, storing the information in an XML file may not be practical. Including additional text to describe data structures may affect how quickly the application responds. You can decide whether XML is the best choice by determining whether response speed is critical and considering how the data is currently stored. You should also take into account how the data will be maintained . While you consider whether to use XML, youll also be able to determine whether youll need server-side interaction within your application.

Is response speed an issue?

When asked, most people will say that its important to have a Flash application that works quickly. In most applications, however, a delay of 2 or 10 seconds is unlikely to be significant. Typically, youll only need to consider response speed if you have large-scale or enterprise-level applications. Large-scale applications have a large number of concurrent users and complex data.

By its very nature, working with XML data in Flash is a slow process. XML information consists of text information sent over HTTP. The larger the XML document, the longer it takes to send. When Flash receives the information, it has to work through the document tree to locate specific information. As a result, you might find that large XML documents or those with a complex structure take many seconds to load and parse in Flash. This may be an unacceptable delay for enterprise-level applications.

If speed is critical, youll get the fastest response times if you use Flash Remoting to interact with the data. Flash Remoting allows a movie to call remote methods as if they were local. This means that you create your functions using server-side files but call them directly in Flash. Your server-side files process the content and provide the processed information to Flash. Server-side processing is always quicker than processing within Flash, so youll save time. Flash Remoting is also quicker because it uses Action Message Format (AMF), a compressed binary format. This reduces the size of content sent to Flash.

Another advantage of Remoting is that the variable datatypes are preserved. An array from a server-side file arrives as an array in Flash when youre using Remoting. The movie can use the array without processing it first. This is quite different from using the LoadVars and XML objects, where content arrives as strings. You need to use ActionScript to process the strings and convert them to other types of variables .

The disadvantage of Flash Remoting is that, unlike an XML document, an AMF message cant be read easily by humans . It is also a proprietary Macromedia format, and youll have to invest money to use it in a commercial environment.

If speed isnt critical in your application, its worthwhile looking at the current location of the data.

Where is the data stored?

The other important issue to consider is where the data is currently stored. As a general principle, you shouldnt change the data storage mechanism without good reason. Data is usually stored in XML documents, databases, or other software packages.

XML document

If the data is already stored in one or more XML documents, then it makes sense to keep it in that format. This includes information stored in physical files as well as data that exists as an information stream. Web services are an example of a stream of XML data.

If data already exists in XML format, theres no sense in adding another step to the process by transforming the data into a text file or inserting it into a database first. Youll just increase processing time unnecessarily. Bear in mind that its possible to apply an XSL transformation to change the structure of an existing XML document to one that is more suitable for use in Flash.

Your approach depends on the type of application that youre creating. If the application will run from a CD-ROM in stand-alone mode, youll only be able to use physical XML documents. When people run applications from CDs, you cant guarantee that theyll have access to the Internet. Youve no way of ensuring that they will be able to connect to a web server to request an XML information stream.

You can use a server-side file to save the XML stream as a physical XML document. The stand-alone Flash application can then load the physical XML document without accessing a web server.

If youre consuming web services, youll also need to consider Flash Player security. You cant consume data from another domain or subdomain in Flash unless the remote application has a policy file in effect. If there is no policy file, youll need to use a server-side file to proxy the data locally. You can find out more about security in Chapter 4.

Database

If your information is stored in a database, youll need to use a server-side file to request the content. The server-side file will need to convert the results into a format that Flash can understand. You can generate variable pairs for use with a LoadVars object. You can also generate an XML document. There is no clear advantage in using either approach, so the choice is really up to you.

Some databases support XML queries that return the content in XML format. If this is the case, your server-side file will be able to return XML directly to Flash. Flash can then load the contents into an XML document tree for inclusion in your movie. This is likely to be quicker than using the server-side file to generate the content. If your database provides this functionality, this should be your preferred option.

Again, if your application is running offline, for example, on a CD-ROM, you wont be able to guarantee access to a web server. Youll have to create the content from the database in physical fileseither text or XML files.

Other software package

XML is such a pervasive technology that many software packages allow you to import and export data in XML format. As well as popular databases, many survey, e-commerce, and contact management software packages allow you to exchange data in this way.

While other software packages are unlikely to interact directly with Flash, you can use them to generate physical XML files. Flash can then load the content using the XML class or data components . By using physical documents, youll make your application portable so you can distribute it on a CD-ROM. Using an XML layer between Flash and your enterprise-level applications also provides extra security that prevents users from accessing sensitive corporate information.

If the data is stored in a software package without XML support, youll need to export it and manipulate the data into a structure that Flash can understand. You could re-create the data using either variable pairs or XML. Again, theres no clear advantage to either approach. You can use a text or XML editor to restructure the data, or you could write a server-side file to automate the process.

Office 2003 document

PC users who have data stored in Office 2003 documents can use Word, Excel, or Access to generate XML content. I covered this in chapters 5, 6, and 7.

Unfortunately, Macintosh Office users dont have access to the same functionality. If youre a Mac user or your data is stored in an earlier version of Office, youll have to re-create the data for Flash. You could create either an XML file or a text file containing variable pairs.

How will the data be maintained?

Its also important to take into account how youll maintain the data that youll use in your Flash application. You saw earlier in this book that its possible to maintain XML content using Office 2003. If the data already exists in Word, Excel, or Access 2003, it makes sense to use an XML format and thus allow the user to update the content themselves . It may even be possible to create new Office 2003 documents to store the data or transform existing data from other sources. You can find out more about Office 2003 and XML in chapters 5, 6, and 7.

Do you need server-side interaction?

Youll need server-side interaction with your XML Flash movie in the following situations:

  • You need to use Flash Remoting to ensure quick response times.

  • You need to proxy XML data, that is, there is no policy file for data from a different domain or subdomain.

  • You need to update the XML content in a Flash movie.

  • You need to create a physical XML document from an XML information stream.

Although it may not change your decision to use XML, youll need to be aware of the additional requirements of using server-side files in your application. Youll need to install the application on a web server and write the server-side functionality using a language such as ColdFusion, PHP, or ASP.NET. You cant easily distribute applications that use server-side functionality on CD-ROMs.

Making the decision

Ive summarized the decision points weve discussed so far in Table 11-1.

Table 11-1: Data storage decision points.

Current Storage Mechanism

Considerations

Decision

Any

Application speed is critical.

Use Flash Remoting and server-side files.

Physical XML document

 

Use the existing XML document in Flash.

Web service

 

Consume web service in Flash. If no policy file exists, use a server-side file to proxy the information or save to a physical file for offline applications.

Database

The database supports XML queries.

Use XML information streams generated by a server-side file. Generate a physical XML document for offline applications.

Database

The database doesnt support XML queries.

Transform content into either XML or variable pairs using server-side files. Generate a physical document for offline applications.

Office 2003 (PC)

 

Export content as XML document(s). Word and Excel are likely to require a schema document to streamline the process.

Office 2003 (PC)

User needs to be able to maintain XML content.

Maintain content in Word, Excel, or Access 2003 and export XML documents for use in Flash. Word and Excel are likely to require a schema document to streamline the process.

Other Office

 

Create physical text or XML file containing content.

Other application

The software supports XML export.

Export content as XML document(s).

Other application

The software doesnt support XML export.

Create physical text or XML file containing content.

The rest of this chapter assumes that youve decided to use XML to provide data for your Flash application. In the next sections, well examine the decisions that youll need to make when choosing how best to incorporate XML content in Flash.



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

Similar book on Amazon

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