Getting Started with the PureMVC Startup Manager – Part 1

Coming from a Flex/Cairngorm background, I’ve always missed a utility that takes care of the asynchronous loading of resources during application startup. Being too lazy to write one myself, I usually chain together several Cairngorm commands for loading configuration settings, stylesheets, language resources and initial data from a database. Each command is only executed if the predecessor task has been finished successfully. The user interface isn’t initialized until the whole chain is completed, otherwise an error message is generated and the application won’t start. It’s not elegant but it works.

When I started to learn PureMVC (and I’m still learning), I was happy to discover that the AS3 version is accompanied by a Startup Manager. This utility isn’t part of the core PureMVC framework and has to be downloaded and installed separately, but it nicely integrates with the “PureMVC way of things”.

There’s a very well-documented sample project (Startup as Ordered) from the author of the utility, Philip Sexton. After exploring the source code of this project, I thought I give it a try and set up my own little startup sequence. Philip’s sample just simulates the asynchronous loading with the help of another utility he wrote (Asynchronous Stub), so I decided to take a more real-world scenario where an external stylesheet and an XML file are loaded before the user interface is created. Once you have understood the basic setup, it’s no big deal to extend the startup sequence by, for example, making asynchronous calls to remote services.

Preparing the Project Space

Loading a stylesheet and some initial data is a common task in both Flash and Flex projects. So my approach in this tutorial is to set up a pure AS3 project that can easily be adjusted to work in both worlds. This also means that you can use whatever IDE you prefer for ActionScript coding. I’m using FlashDevelop along with the Flex 3 SDK but the project space would look very similar in FlexBuilder.

If you haven’t already done so, download the PureMVC framework and the Startup Manager. Make sure that both libraries are available to your project. Either copy the SWC files in your project space or add their locations to the classpath. On the top level, your project should contain the three folders bin, lib and src. For my purposes, I placed copies of the SWC files in the lib folder so that I can provide a working FlashDevelop project for download that includes all resources.

Choose a package name (I’m going to use com.log2e.puremvcdemo) and create the usual model, view, controller folders. Also, in addtion to your document class (Main.as) create an empty file with the name ApplicationFacade.as in the puremvcdemo folder. You project panel should look similar to this now:

Project Panel

The Resource Files: styles.css and data.xml

Inside the bin folder create two text files with the names styles.css and data.xml. These are the resources that we will be loading during startup. The stylesheet is pretty simple:

  1. .title {
  2.    font-size:16px;
  3.    font-family:Arial,Helvetica,sans-serif;
  4.    font-weight:bold;
  5.    color:#990000;
  6. }
  7.  
  8. .label {
  9.    font-size:14px;
  10.    font-family:Arial,Helvetica,sans-serif;
  11.    font-weight:bold;
  12.    color:#999999;
  13. }
  14.  
  15. p {
  16.    font-size:12px;
  17.    font-family:Arial,Helvetica,sans-serif;
  18.    color:#333333;
  19. }

The XML file contains some sample content:

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <site>
  3. <title>Welcome to the PureMVC Startup Manager Demo!</title>
  4. <sections>
  5. <section id="1" label="Home">
  6. <content>
  7. <![CDATA[<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Quisque consequat. Nam ut leo <i>vitae metus vehicula</i> posuere. Nullam nunc. Vivamus nec ligula vel tortor molestie elementum. Integer faucibus elementum dolor. Nulla lorem. Quisque varius sodales mi. Nam tincidunt pede. Nam scelerisque nulla a nisl.</p>
  8. <p>Vivamus nec ligula vel tortor molestie elementum. Nam ut leo vitae metus vehicula posuere. Nullam nunc. Vivamus nec ligula vel <b>tortor molestie elementum</b>. Integer faucibus elementum dolor. Nulla lorem. Quisque varius sodales mi. Nam tincidunt pede. Nam scelerisque nulla a nisl. Quisque consequat.</p>]]>
  9. </content>
  10. </section>
  11. </sections>
  12. </site>

Important note: Make sure that the HTML-coded content inside the CDATA block is only composed of HTML tags that can be interpreted by HTML-enabled textfields in Flash/Flex.

In the next part of this tutorial we will be taking a closer look at the inner working of the Startup Manager.


You can download the sample files from here (the ZIP archive includes a FlashDevelop project file). If you want to comment on this tutorial please post in the comments section at the end of the introductory post.

Tags: , , , ,

3 Responses to “Getting Started with the PureMVC Startup Manager – Part 1”

  1. [...] für den StartupManager empfehle ich die 3-teilige Anleitung aus Stefan Schmalhaus’ log2e Blog: Teil 1, Teil 2 und Teil 3. Obwohl er laut Blog aus Krefeld kommt, sind diese Anleitungen allerdings in [...]

  2. [...] Getting Started with the PureMVC Startup Manager [...]

  3. [...] 最後補充兩個網站連結介紹的滿詳細的提供給大家參考1. Getting Started with the PureMVC Startup Manager – 1, 2, 32. 10 tips for working with PureMVC [...]