Accessibility

Table of Contents

Creating a Flash Lite 1.1 RSS Reader

Creating the Flash Lite 1.1 reader

Now let's create a Flash Lite RSS reader client. Start by creating rss-reader.fla with five frames and two layers. Figure 1 shows the Timeline.

Frames 1-5 of the Timeline

Figure 1. Frames 1–5 of the Timeline

The first frame contains the following ActionScript code (see Figure 2).

Frame 1, ActionScript

Figure 2. Frame 1, ActionScript

The HTTP variable is the link to your RSS reader script on the server. The content of the first frame contains a button (see Figure 3) that will go to the second frame using the following ActionScript:

on (press) {
    gotoAndPlay(2);
}
Frame 1, UI

Figure 3. Frame 1, UI

In the second frame, make the call to the server using the loadVariable function using the link to the rss-reader.php file on the server (see Figure 4).

Frame 2, ActionScript

Figure 4. Frame 2, ActionScript

Then set the end variable to null to make sure that is always reset before making a call to the server (see Figure 5).

Frame 2, UI

Figure 5. Frame 2, UI

The Back button contains the following code:

on (keyPress "<PageUp>") {
    gotoAndPlay(1);
}

Note that this button is placed across frames 2, 3, and 4.

Frame 3 is the same as Frame 2 but will not contain any code. It will be used for the loop to load the data. On Frame 4, check if the data is loaded or not. If the data from the server is loaded, it will go to Frame 5; otherwise it will go back to Frame 3. It is possible to use other methods for waiting and loading the data, but this is pretty straightforward and easy to implement. Figure 6 shows the ActionScript on Frame 4.

Frame 4, ActionScript

Figure 6. Frame 4, ActionScript

If the end variable is not equal to "end", it means that the data is still loading, the gotoAndPlay(3) code is executed, and the application goes to the previous frame, Frame 4.

If the end variable is equal to "end", it means that the data is been completely loaded. Remember the rss-parser.php script?

echo "&end=end";

This line of code is located in two places: when data is returned and when there is no data to be returned (check the parser PHP code). The code in Figure 6 takes care of both these cases. If the variable flag is not equal to "flag", everything is fine and it can go to next frame, Frame 5.

On the other hand, if the end flag is not equal to "flag", it stops and shows an error message inside a dynamic text field (with the following variable: msg) on the same Frame 4 (see Figure 7). In this case, you can define an error message with the following PHP code sent by the server:

echo "&msg="Content not found";
echo "&flag=error";

Defining the error code in the server API is of particular interest because I will be able to change the message without the need of modifying the client application.

Frame 4, error message

Figure 7. Frame 4, error message

Tip: The above messaging method is very flexible if you develop Internet-aware applications. You can always change messages on the server side without the need to create a new client application.

Figure 8 shows the ActionScript on Frame 5. It's evaluating the content of the title1 and description1 variables sent by the server.

Frame 5, ActionScript

Figure 8. Frame 5, ActionScript

Frame 5 will display the RSS title and description text (see Figure 9). It will have two dynamic text fields with variables set to title and description, a back button, and an SMS button. It will also have a hidden button to perform the scrolling of the description text and the browsing of the different variables sent by the server:

echo "&title$i=".$title;
echo "&description$i=".$description;
Frame 5

Figure 9. Frame 5

Notice that there will be as many variables as the number of items present in the XML feed. Also, two other dynamic text items are shown, one to show the total number of items loaded, totalitems, and the other to show the current item number, n.

Finally here is the ActionScript for the two buttons in Frame 5:

Back button

on (keyPress "<PageUp>") {
    gotoAndPlay(1);
}

SMS button

on (keyPress "<PageDown>") {
    getURL("sms:?&body=" add title add newline add description); 
}

Hidden button

This is used to select the variables title and description and to scroll the dynamic text contained in the description variable:

// Shifting variables
on (keyPress "<Right>") {
    if (n ne totalitems) {
        n++;
    } else {
        n = 1;
    }
    title = eval("title" add n);
    description = eval("description" add n);
}
on (keyPress "<Left>") {
    if (n ne 1) {
        n- -;
    } else {
        n = totalitems;
    }
    title = eval("title" add n);
    description = eval("description" add n);
}
//Scrolling
on (keyPress "<Up>") {
    description.scroll--;
}
on (keyPress "<Down>") {
    description.scroll++;
}

The Flash Lite 1.1 RSS reader is now complete (see Figure 10).

Completed Flash Lite 1.1 RSS reader

Figure 10. Completed Flash Lite 1.1 RSS reader

Where to go from here

You now have the basic framework of a Flash Lite 1.1 RSS reader. You now can create your own RSS reader for blogs, news, or RSS feeds.

Having a server-side RSS parser offers great flexibility, given that RSS feed links sometimes change. You will need to change the link location in the server script, but your Flash Lite 1.1 RSS reader will stay the same without needing an update.

Also, using the Flash Lite 1.1 &name=value data structure offers cost savings for the mobile user compared to XML. In many countries, mobile data is paid for by the kilobyte, which means that XML verbosity is more expensive than the &name=value data in Flash Lite 1.1.

For more information, visit the Flash Lite Developer Center and subscribe to the Adobe RSS feeds.