views:

1110

answers:

4

In the Flex framework a custom preloader can be used while the site is loading.

In the Adobe docs it specifies that 'the progress bar [preloader] is displayed if less than half of the application is downloaded after 700 milliseconds of downloading.'

However I ALWAYS want the preloader to appear instantly since I know that 95% of our users are first time visitors and the site is over 500kb. I dont want people to have to wait .7 seconds for the preloader animation to appear.

I would think in theory that it is possible to 'monkey patch' the framework to remove this .7 second limitation. I dont have time to figure out how, and I've never done it before.

Anybody help?

+1  A: 

This is in mx.preloaders::DownloadProgressBar.as, line 1205 in the showDisplayForDownloading function.

Old school monkey-patching is out with AS3, but you can either edit the Flex source and compile yourself a new framework.swc (apparently a pain), or just include it in your source path (source paths override .swcs); or derive your own preloader class from DownloadProgressBar that just overrides showDisplayForDownloading and returns true.

You can find the framework source in '%PROGRAMFILES%\Adobe\Flex Builder 3[ Plug-in]\sdks\3.0.0\frameworks\projects\framework\src', then the package path. Change the sdk version if you are using 3.1, or whatever.

Simon Buchan
I'd recommend just sub-classing the DownloadProgressBar class.
Sly_cardinal
+4  A: 

You should just extend the DownloadProgressBar, try the following code. i've used this before and I've found jesse warden site click here usful for info on this (where I found out about it and this is a cut down version of his code)

package{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;

import mx.events.FlexEvent;
import mx.preloaders.DownloadProgressBar;

public class Preloader extends DownloadProgressBar
{

 /**
 * The Flash 8 MovieClip embedded as a Class.
 */  
 [Embed(source="yourPreloaderFile.swf")]
 private var FlashPreloaderSymbol:Class;

 private var clip:MovieClip;

 public function Preloader()
 {
  super();
  clip = new FlashPreloaderSymbol();
  addChild(clip);
 }

 public override function set preloader(preloader:Sprite):void 
    {                   
        preloader.addEventListener( FlexEvent.INIT_COMPLETE ,   onFlexInitComplete );

        centerPreloader();
    }

    private function centerPreloader():void
 {
  x = (stageWidth / 2) - (clip.width / 2);
  y = (stageHeight / 2) - (clip.height / 2);
 }

    private function onFlexInitComplete( event:FlexEvent ):void 
    {
        dispatchEvent( new Event( Event.COMPLETE ) ); 
    }


    protected override function showDisplayForDownloading(time : int, event : ProgressEvent) : Boolean {
        return true;
    }

}

}

after that just change the preloader property in the main application tag to the Preloader class.

A: 

I'd guess that delay is there for two reasons:

  1. You don't want the preloader to "blink" in once the page is already cached
  2. The preloader itself has to load

When I need to make absolutely sure a preloader is shown instantly I make a small wrapper swf that has just the preloader and load the main swf from there.

grapefrukt
A: 

its not possible to make preloader show instantly , since some classes needs to be downloaded before progress can be displayed . other alternative can be that you display a progress in html and when flash movie is loaded it shows up but here .

Bryson