There are a few fundamental concepts to understand about Flex and Flash before getting started:
The CEO of My Virtual Pet, Inc. (MVP for short) shakes your hand, welcomes you on board, and reiterates his well-founded confidence in your ability to make their award-winning Virtual Pet software into a Rich Internet Application.
Along with your detailed specification, and a last-minute warning that MVP intends to keep ahead of their competition by releasing a new behavior for their pets every few days over the next year, you head back to your trusty computer and start designing.
With your design pattern book in hand, you map out your classes and conclude that the basic implementation is a piece of cake. You see really only two problems:
Instead of filling this article with implementation details for the Virtual Pet application, I assume that you will design the pets to the MVP specification. To demonstrate the version synchronization topics, you will use a simple class (Dog) to represent that work.
Find the sample code in virtual_pet1.mxml, located in the accompanying file downloaded in the Requirements section of this article:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" xmlns="*">
<Dog id="myPet"
title="Virtual Pet RIA">
petName="Spike"/>
</mx:Application>
This is your starting point: a simple application that instantiates a Dog. The Dog class puts a picture of the dog on the screen and lets him introduce himself (see Figure 1).
Figure 1. Dog class introducing itself as Spike
Today Spike can bark, wag, and roll over but you need to ensure that Spike can learn new tricks in the future. Therefore, you need to provide a mechanism for future updates.
There are two groups of Virtual Pet users. Some users close down their web browsers or turn off their computer every day. Flex automatically takes care of these users because when they return to the MVP website, Flex provides them with the latest version. The other set of users keep their web browsers open for the life of their pet. They are your focus at this point.
The always-connected users do not intend to close their web browsers or go back to the MVP site. There are two relatively easy ways to deal with them.