The Flash to Flex series has covered the basic creation of a Flex project and making a move to ActionScript 3 (AS3). In this article we will take a deeper look at class creation in Flex and learn how to develop a reusable component for displaying and rotating headlines in any Flex application.
The source code for the example in this article can be downloaded here.
Defining an XML Structure
When creating an XML-driven component, the first logical step is to define the XML structure that it will request so we can understand how to parse it.
In this example, we will create a component that rotates between multiple headlines and displays them as hyperlinks that we define the URLs for. Listing 1 shows an example of the XML structure that we will use in the component.
Listing 1: XML structure for headlines
<?xml version="1.0" encoding="ISO-8859-1" ?> <headlines> <headline action="http://www.studiosedition.com"><![CDATA[Visit Studio Sedition]]></headline> <headline action="http://www.studiosedition.com/articles"><![CDATA[View all of my articles]]></headline> </headlines>
The structure has the capability to add multiple headlines as CDATA to enable HTML rendering, and each headline has an action attribute that points to a URL. Now that we have our XML structure, let’s start creating our component.