Consuming an RSS Feed

As we mentioned earlier, RSS stands for Rich Site Summary, RDF Site Summary, or Really Simple Syndication (depending on which article you read). RSS is an XML vocabulary that describes information about website changes, so this makes it ideal for sharing news. Netscape originally developed it as a way to provide news through different news channels.

RSS comes in a number of versions, each one using slightly different XML elements. Learn more about each version at www. webreference .com/authoring/languages/xml/rss/1/.

You need to consider Flash Player security when consuming an RSS feed. If theres a cross-domain policy file on the server providing the feed, you can consume the content directly in a Flash movie. If not, youll need to use a server-side file to proxy the content locally.

In the next section, well look at an example of consuming an RSS feed using the XMLConnector component. Youll need to have Flash Professional and an active Internet connection to complete this exercise. The RSS feed comes from Macromedia and has a cross-domain policy in place, so we dont need to use a server-side file to proxy the data.

Exercise 2: Consuming a news feed using the XMLConnector
image from book

In exercise 2, well use the XMLConnector component to load the news feed from This news feed provides information about Flash from the Developer Center. You can find out more about the available Macromedia RSS feeds at

  1. Enter the URL in a web browser. You should see the structure of the XML document in the browser window. In some web browsers, the file may open in a different application. Figure 9-4 shows this XML document open in Internet Explorer.

    image from book
    Figure 9-4: The Flash RSS feed

  2. Open Flash if necessary and open the starter file FlashRSS.fla . Figure 9-5 shows the interface.

    image from book
    Figure 9-5: The Flash RSS interface

  • The Flash file has a List component and two TextArea components . There is also a button component called visit_btn . Well load the articles into the List component. When we click one of the titles, the details and link will display in the TextArea components. We can view the article in a web browser by clicking the Visit button.

  1. Drag an XMLConnector component into the movie and position it off the Stage. Give it the instance name rss_xc .

  2. Select the XMLConnector and open the Component Inspector. Enter the URL and set the direction to receive .

  3. Select the Schema tab and choose results . Select the read only setting and choose true . Load a schema from the document flashRSSSample.xml . I saved this document from the RSS feed. It contains a trimmed -down version of the data and provides a structure for Flash to use. You can open the file in a text or XML editor if you want to see what it contains. Figure 9-6 shows the schema generated from the file.

    image from book
    Figure 9-6: The schema imported from flashRSSSample.xml

  4. Create a new layer called actions and add the following code on frame 1:


    This code triggers the XMLConnector component to load the data from the RSS feed. Once the data is loaded, well need to display the headings in the List component. Well do this by adding a binding.

  1. Select the XMLConnector and choose the Bindings tab in the Component Inspector. Click the Add binding button and add a binding from the item array. Set the direction to out and bind the item to the dataProvider of the List component. If we want to display multiple values from the results, its common to bind from an array to the dataProvider of a data-aware component such as a List or ComboBox.

  2. Choose a Rearrange Fields formatter and add label=title to the formatter options. This specifies what field should display in the List.

  3. Test the Flash movie and check that the List component populates correctly. Figure 9-7 shows the interface at this stage.

    image from book
    Figure 9-7: The interface with the loaded content

    Well need to add bindings to the TextArea components. When we click a heading, the description should appear in the Details TextArea while the link should display in the Link TextArea.

  4. Select the XMLConnector and add a binding from the description element. Set the direction to out and bind the description to the text property of the details_txt component. Set the Index to the selectedIndex property of the List component. Weve told the XMLConnector to display the description for whichever item is selected in the List.

  5. Repeat the process to bind the link element to the text property of the link_txt component. Set the Index to the selectedIndex property of the List component.

  6. Test the movie. When you select a List item, you should see the description and title within the TextArea components. Figure 9-8 shows the interface.

    image from book
    Figure 9-8: The interface showing the bound components

  1. The final step is to configure the Visit button so that the selected article displays in a web browser. Add the following code to the actions layer. The code checks to see if there is any text within the link_txt component. If so, it loads the link using the getURL action.

     visit_btn.onRelease = function ():Void {   if (link_txt.text.length > 0) {     getURL(link_txt.text);   } } 
  2. Test the Flash movie. You should be able to select an item from the List component and click the Visit button to open the article in a web browser window. You can see the completed file saved as FlashRSS_completed.fla .

Points to note from exercise 2

  • When tested from Flash, this movie loads the URL into a new web browser. As with the previous exercise, you could add a JavaScript function to the HTML page hosting the movie so that the link loads in a new browser window. Youd have to call this function from with the onRelease function of the Visit button.

  • This movie loads data from an external domain directly into Flash. When you test the movie from Flash, you can load the data successfully, even though it is coming from another domain.

    Because this RSS feed has a cross-domain policy in place, youll be able to load the data into a Flash movie on any web server. If there were no cross-domain policy, youd need to find a workaround for the Flash player security restrictions. One option would be to proxy the data using a server-side file. You saw an example of how to do this in exercise 1. You can find out more about security in Chapter 4.

So far, weve looked at REST and RSS, and youve created two applications to display data. A more common protocol for web services is SOAP. Flash can automate the process of making a SOAP request for you.

image from book

Foundation XML for Flash
Foundation XML for Flash
ISBN: 1590595432
EAN: 2147483647
Year: 2003
Pages: 93
Authors: Sas Jacobs © 2008-2017.
If you may any questions please contact us: