Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6770025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:15:47+00:00 2026-05-26T15:15:47+00:00

I have been digging for custom Flex preloaders and they all seem to rely

  • 0

I have been digging for custom Flex preloaders and they all seem to rely on the same template:
An SWC is created with Flash CS5 and then used by Flash Builder using the “preloader” application property.

I don’t own Flash CS, and it feels that Flash builder should be able to do the trick.
I created a Library Project in Flash Builder with the following bare bones code:

package loader  
{
    import flash.display.DisplayObject;
    import flash.events.Event;
    import flash.utils.getTimer;

    import mx.events.RSLEvent;
    import mx.preloaders.DownloadProgressBar;
    import mx.preloaders.SparkDownloadProgressBar;      

    public class Preloader extends SparkDownloadProgressBar
    {

        [Embed(source="loaderlogo.png")] public var logoClass:Class;

        private var _displayStartCount:uint = 0; 
        private var _initProgressCount:uint = 0;
        private var _downloadComplete:Boolean = false;
        private var _showingDisplay:Boolean = false;
        private var _startTime:int;
        // private var preloaderDisplay:PreloaderDisplay;
        private var rslBaseText:String = "loading: ";


        public function Preloader()
        {
            super();
        }

        /**
         *  Event listener for the <code>FlexEvent.INIT_COMPLETE</code> event.
         *  NOTE: This event can be commented out to stop preloader from completing during testing
         */
        override protected function initCompleteHandler(event:Event):void
        {
            dispatchEvent(new Event(Event.COMPLETE)); 
        }

        /**
         *  Creates the subcomponents of the display.
         */
        override protected function createChildren():void
        {    
            var img:DisplayObject = new logoClass();
            img.x = Math.round( ( stageWidth - img.width) / 2);
            img.y = Math.round( ( stageHeight - img.height) / 2);
            addChild( img);

            var dpb:DownloadProgressBar = new DownloadProgressBar();
            dpb.x = img.x + 100;
            dpb.y = img.x + 100;
            dpb.width = 170;
            dpb.height = 20;
            addChild( dpb);
        }

        /**
         * Event listener for the <code>RSLEvent.RSL_PROGRESS</code> event. 
         **/
        override protected function rslProgressHandler(evt:RSLEvent):void {
            if (evt.rslIndex && evt.rslTotal) {
                //create text to track the RSLs being loaded
                rslBaseText = "loading RSL " + evt.rslIndex + " of " + evt.rslTotal + ": ";
            }
        }

        /** 
         *  indicate download progress.
         */
        override protected function setDownloadProgress(completed:Number, total:Number):void {

        }

        /** 
         *  Updates the inner portion of the download progress bar to
         *  indicate initialization progress.
         */
        override protected function setInitProgress(completed:Number, total:Number):void {
        } 


        /**
         *  Event listener for the <code>FlexEvent.INIT_PROGRESS</code> event. 
         *  This implementation updates the progress bar
         *  each time the event is dispatched. 
         */
        override protected function initProgressHandler(event:Event):void {
            var elapsedTime:int = getTimer() - _startTime;
            _initProgressCount++;

            if (!_showingDisplay &&    showDisplayForInit(elapsedTime, _initProgressCount)) {
                _displayStartCount = _initProgressCount;
                show();
                // If we are showing the progress for the first time here, we need to call setDownloadProgress() once to set the progress bar background.
                setDownloadProgress(100, 100);
            }

            if (_showingDisplay) {
                // if show() did not actually show because of SWFObject bug then we may need to set the download bar background here
                if (!_downloadComplete) {
                    setDownloadProgress(100, 100);
                }
                setInitProgress(_initProgressCount, initProgressTotal);
            }
        }

        private function show():void
        {
            // swfobject reports 0 sometimes at startup
            // if we get zero, wait and try on next attempt
            if (stageWidth == 0 && stageHeight == 0)
            {
                try
                {
                    stageWidth = stage.stageWidth;
                    stageHeight = stage.stageHeight
                }
                catch (e:Error)
                {
                    stageWidth = loaderInfo.width;
                    stageHeight = loaderInfo.height;
                }
                if (stageWidth == 0 && stageHeight == 0)
                    return;
            }

            _showingDisplay = true;
            createChildren();
        }

    }
}

For short, it’s loading a logo and a progress bar
It displays a preloader, but really late in the loading process. As if it was being loaded after Flex.
Do I need to compile this in CS5 to completely avoid use of MX/Spark?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:15:48+00:00Added an answer on May 26, 2026 at 3:15 pm
    1. You shouldn’t use any components in preloader. Try to remove you imports (Ctrl+Shift+O):

      import mx.controls.Image;
      import spark.components.Label;

    2. Use TextField and Loader instead if needed. I’m not sure about DownloadProgressBar component.

    Also don’t use create children in preloader. Here is one working sample:

    package {
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.ProgressEvent;
    import flash.text.TextField;
    import flash.text.TextFormat;
    
    import mx.core.mx_internal;
    import mx.preloaders.SparkDownloadProgressBar;
    
    use namespace mx_internal;
    
    public class Preloader extends SparkDownloadProgressBar {
    
        private var preloaderLogo : MovieClip;
        private var loadingText : TextField;
        private var loadingProgress : TextField;
    
        private var _initProgressCount : uint = 0;
    
        private var textFormat : TextFormat = new TextFormat("Verdana", 16, 0x666666, true);
    
        public function Preloader() {
            super();
    
            textFormat.align = "center";
        }
    
    
        override public function set preloader(value : Sprite) : void {
            super.preloader = value;
    
            if (!preloaderLogo) {
                preloaderLogo = new Assets.PRELOADER_LOGO;  // kakaranet logo
    
                var startX : Number = Math.round((stageWidth - preloaderLogo.width) / 2);
                var startY : Number = Math.round(stageHeight / 2 - preloaderLogo.height) - 100;
    
                preloaderLogo.x = startX;
                preloaderLogo.y = startY;
    
                loadingText = new TextField();
                loadingProgress = new TextField();
    
                loadingText.width = stageWidth;//to allow center align
                loadingProgress.width = stageWidth;                
    
    
                loadingText.text = "Loading...";
                loadingText.y = preloaderLogo.y + preloaderLogo.height + 20;
    
    
                loadingProgress.text = "0%";
                loadingProgress.y = loadingText.y + loadingText.textHeight + 10;
    
                addChild(preloaderLogo);
                addChild(loadingText);
                addChild(loadingProgress);
    
                loadingText.setTextFormat(textFormat);
                loadingProgress.setTextFormat(textFormat);
            }
        }
    
    
        override protected function progressHandler(event : ProgressEvent) : void {
            super.progressHandler(event);
            if (loadingProgress) {
                loadingProgress.text = Math.floor(event.bytesLoaded / event.bytesTotal * 100) + "%";
                loadingProgress.setTextFormat(textFormat);
            }
    
        }
    
        override protected function completeHandler(event : Event) : void {
            loadingText.text = "Ready!";
            loadingText.setTextFormat(textFormat);
            preloaderLogo.stop();
        }        
    
    
        override protected function initProgressHandler(event : Event) : void {
            super.initProgressHandler(event);
            //similar to super
            _initProgressCount++;
            if (loadingProgress) {
                loadingProgress.text = "100% / " + Math.floor(_initProgressCount / initProgressTotal * 100) + "%";
                loadingProgress.setTextFormat(textFormat);
            }
        }
    }
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been recently digging into Mobile Programming, I practically tried out the J2ME
I have been digging around on this site and googling for a while now
I have been having issues with a custom check box control for a while
I have been digging internet for couple days, reading very old information, that leads
I have been digging into the question for a while in StackOverflow Android get
I have been digging since last three days to find out the appropriate way
Im completely new to XML/XSL/XSLT, and while i have been digging msdn, 3schools.com and
I have been working on generating all possible submodels for a biological problem. I
Have been digging around the docs but cannot find if there is a function
I have been digging codeigniter for some hours. I found some different regex in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.