0 Replies Latest reply on Aug 23, 2011 2:23 AM by Manno Bult

    loading progress bar in AS3 project compiled with Flex

    Manno Bult Level 1

      Hi all,

       

      I'm having problems implementing Keith Peter's posted sollution to having a progessbar indicating load progress of a single SWF compiled with Flex (4.5.1 in this case)

       

      Original post is: http://www.bit-101.com/blog/?p=946 with a slightly more elaborate examples posted at: http://www.actionscript.org/forums/showthread.php3?p=1076780.

       

      Either of the two methods it fails to show any inflating rect. Testing with some textual output it shows it has two frames but it shows only the graphic output from the main class. Below is the easiest method to post not being dependent on compiler arguments. Can anyone see what goes wrong?

       

      Thanks in advance,

      Manno

      // the main class, the 'runnable application file' 
      package
      {
           import flash.display.Sprite;
           import flash.events.Event;
           [Frame(factoryClass="Preloader")]
           public class PreloadedApplication extends Sprite
           {
                     [Embed( source="assets/ot.jpg" )]
                private var image:Class;
                
                public function PreloadedApplication()
                {
                     trace( "main class started" );
                     addEventListener( Event.ADDED_TO_STAGE, init );
                }
           
                private function init( event:Event ):void
                {
                     removeEventListener( Event.ADDED_TO_STAGE, init );
                     var b:Bitmap = new image() as Bitmap;
                     b.width = stage.stageWidth;
                     b.height = stage.stageHeight;
                     addChild( b );
                }
           }
      }
      
      // the factory class that should show the preloader 'animation'
      package
      {
           import flash.display.MovieClip;
           import flash.events.Event;
           import flash.utils.getDefinitionByName;
           
           public class Preloader extends MovieClip
           {
                public function Preloader()
                {
                     addEventListener( Event.ENTER_FRAME, checkLoaded );
                     stop();
                }
                
                protected function checkLoaded(event:Event):void
                {
                     if( totalFrames == framesLoaded )
                     {
                          trace( "loaded" );
                          this.graphics.clear();
                          removeEventListener( Event.ENTER_FRAME, checkLoaded );
                          nextFrame();
                          init();
                     }
                     else
                     {
                          var fraction:Number = root.loaderInfo.bytesLoaded / root.loaderInfo.bytesTotal;
                          trace( fraction );
                          this.graphics.clear();
                          this.graphics.beginFill( 0x00FF00 );
                          this.graphics.drawRect( 0, 0, stage.stageWidth * fraction, stage.stageHeight );
                          this.graphics.endFill();
                     }
                }
                
                private function init():void
                {
                     var main:Class = Class( getDefinitionByName( "PreloadedApplication" ) );
                     if( main )
                     {
                          var instance:PreloadedApplication = new main();
                          addChild( instance );
                     }
                }
           }
      }