On CBS News: Amazing videos caught on tape

Create XML solutions for Macromedia Flash MX

Tags: Guest Contributor

  • Save
  • Print
  • Digg This
  • 0

Takeaway: Take your knowledge of XML and put it to the test in Flash. Here's how.

This article originally appeared as a Web Development Zone e-newsletter.

By Phillip Perkins

Macromedia is moving into the application development arena with many of the new features available in Flash 5.0 and MX. One of these features is the XML integration in Flash. Even if you're not a Flash designer, you can take your knowledge of XML and put it to the test in Flash.

Without much effort, you can acquire enough knowledge of Flash to create a complete solution. Flash is based on a movie philosophy in that events usually occur along a timeline, which is divided into frames. However, with ActionScript, you can handle events and navigate a movie without many frames composing the whole movie. In my example, I create a phone directory solution with only one frame.

ActionScript is based on the ECMA-262 standard, so it closely resembles JavaScript. If you're familiar with JavaScript, you won't have any problems adapting to ActionScript.

The phone directory solution that I'll create is a very simple one. You enter the last name or part of the last name of the person for whom you are looking. This last name data is then sent to an Active Server Page (ASP) that uses the query string data in the request to search a Microsoft Access database for a match. The recordset returns, converts to XML, and returns as XML to the Flash movie. The Flash movie then parses the XML and displays the result set.

The Flash movie only contains a text input area for entering the last name data and button to initiate the search. The results are instantiated as individual movie clips from a movie clip symbol. (Instead of going into a complete Flash tutorial, you'll find a link to the source code at the end of this article.)

Flash provides an XML object class for creating XML solutions. The load() method on the XML object allows you to download data from a remote host. When the data is finished downloading, the onLoad event of the XML object occurs.

You can provide an event handler for the XML object by setting this onLoad event to a valid function name. Flash's XML object doesn't provide a great deal of functionality with the retrieved XML. However, with a bit of intelligent design, you can create some witty solutions.

Here's the onLoad event handler for the XML object. Click here.

The first for() loop removes the existing movie clips from the previous result set. The next for() loop iterates through each childNode in the XML object (myXML). A new instance of the phone movie clip symbol is added and positioned on the stage with each loop. The phone movie clip symbol contains several component variables that match the nodeNames of each childNode of the XML document. These are used to set the text of each movie clip instance. One thing to notice is the child.childNodes[0].nodeValue property call. When a normal node is returned with text between the start and end tag, that text is known as a text node. You must refer to the child node of the element to get the contents of that element. Here's a sample of the XML that is being returned:

    <row>
        <first_name>John</first_name>
        <last_name>Public</last_name>
        <phone>800-555-1212</phone>
    </row>

In order to get the XML result set, a button was added to the stage with the following event handler:

btnOK.onRelease = function() {
    myXML.load("getInfo.asp?s=" + m_txtLName);
}

This function requests XML from the getInfo.asp page. The last name is passed in as a query string.

Now for the ASP to handle the request. Click here.

This code grabs the recordset, saves it in XML format, and transforms that XML into usable XML. The XML is then sent out to the Response buffer.

If you'd like the source code to this solution, please copy and paste this URL into your browser:
http://www.geocities.com/phil_perkins_1/Flash/flash.zip

Phillip Perkins is a contractor with Ajilon Consulting. His experience ranges from machine control and client/server to corporate intranet applications.

  • Save
  • Print
  • Digg This
  • 0

What do you think?

Article Categories

Security
Security Solutions, IT Locksmith
Networking and Communications
E-mail Administration NetNote, Cisco Routers and Switches
CIO and IT Management
Project Management, CIO Issues, Strategies that Scale
Desktops, Laptops & OS
Windows 2000 Professional, Microsoft Word, Microsoft Excel, Microsoft Access, Windows XP,
Data Management
Oracle, SQL Server
Servers
Windows NT, Linux NetNote, Windows Server 2003
Career Development
Geek Trivia
Software/Web Development
Web Development Zone, Visual Basic, .NET

advertisement
Click Here