One of the first things you want to do when creating a Flex app is to remove all the default stuff, which makes your app look like everyone else’s. The most obvious default thing in Flex is that loading, progress initilisation bar you get before the application starts.

Now before I start there is one thing to look out for. I first wanted to change the background colour, and kept getting a flash of that Windows 98 turquoise before it change to my new colour… This had me really confused for a while, until I realised that the auto generated HTML that Flex Builder 3 creates has that same colour as it’s default background… Doh! (You can also get the compiler to change this, see the gotoAndLearn example for more info)

Quite a few of the settings of the loading screen can be set through the mx:Application tag, in your Application Class’s MXML. The most obvious being the background colour. This is also where you can specify your own download screen, or as Adobe call it, “DownloadProgressBar”.

At the highest level a Flex application is a two frame movie clip, the first frame being the aforementioned, “DownloadProgressBar” and the second being your Application class. In order to draw images and a progress bar on your loading class thing, you will need to extend the Sprite class (like a movieclip without frames) and implement the IPreloaderDisplay. ( Holy object orientation Batman! Don’t worry you can just copy my example and ignore that if you want!)

When creating your own “DownloadProgressBar” you need to keep it lightweight, otherwise you will have to make a “DownloadProgressBar” for that! Also some elements of the Flex framework won’t be available when it starts, so don’t go too crazy!

The first step is to add this to the tag in your Application’s MXML file

preloader="com.example.preloaders.myDownloadProgressBar"

Once this is added your application will use your custom “DownloadProgressBar” Class, rather than the default one. This means you can do lots of stuff yourself with the information provided, such as total to download and total downloaded, in addition to some events called at various stages of initilisation.

Download the Download Progress Bar example class here. I have commented as much as I can, and will try and put a demo together soon.

Other examples:

  • http://www.onflex.org/ted/2006/07/flex-2-preloaders-swf-png-gif-examples.php
  • http://flexiblemyself.blogspot.com/2007/10/custom-preloader.html
  • http://iamjosh.wordpress.com/2007/12/18/flex-custom-preloader/
  • https://defiantmouse.com/yetanotherforum.net/default.aspx?g=posts&t=82
  • http://www.gotoandlearn.com/play?id=108

This entry was posted on Thursday, March 13th, 2008 at 1:49 pm and is filed under AIR, ActionScript, Development, Flex. You can leave a comment and follow any responses to this entry through the RSS 2.0 feed.

7 Comments Leave a comment

  1. darek 18 August 2008 at 11:52 pm #

    thanks for article, i ve used it in my application

  2. Winzz 17 April 2009 at 11:47 am #

    very usefull tutorial, and very clear, I adapted it for my website, Congratz

  3. Jim 19 May 2009 at 4:27 pm #

    When i get the code from the example, do i put that code into an .as file or a class file? Where is the file then placed? I am getting errors that say the definition could not be found and Access of undefined property within the class.

  4. Rob 19 May 2009 at 5:00 pm #

    @jim. You can put file where ever you want, but it must be given the same name as the class inside (which is called myDownloadProgressBar when you download it). Then you should place it in your src folder, in a folder structure of your choice, normally people use reverse domain syntax, com/pixelbox/preloader/filename.as Once there you can include like so: preloader=”com.pixelbox.preloader.Filename”

    Hope that helps

  5. Royce 23 June 2009 at 3:18 am #

    Thanks a lot for this. It worked brilliantly for us and solved the flickering issue we had with our existing approach. It’s also very CPU effecient… nice one!

  6. [...] к дизайну приложения. В процессе поиска я наткнулся на статью, объясняющую как изменить поведение стандартного [...]

  7. Tommy 26 October 2009 at 5:10 pm #

    A excellent example. Really helped with my application. Great work! :D

Leave a Reply