Methedology: Preloading Robotlegs App

John's Avatar

John

28 Dec, 2011 08:56 PM

Hello,

I've completed an app using the Robotlegs Framework as a flash professional project in Flash Builder 4.6.
All is working great! and my app is completed.

However, due to it's size I want to use a preloader swf to load in the main app.

Question: What is the best approach for this?

I tried making a new project that just loads the swf in the main document class but I'm getting scoping errors as mentioned in this post

http://knowledge.robotlegs.org/discussions/problems/270-using-a-pre...

But after following the fixes and critiques in the post I now find myself a little lost on how this should be implemented.

Can somebody lend me some wisdom on what is the best approach to preloading a robotlegs app.

Thanks!

  1. 1 Posted by Jos on 30 Dec, 2011 03:25 PM

    Jos's Avatar

    I personally use the [Frame(factoryClass="com.example.Preloader")] meta-data, following the example here: http://www.bit-101.com/blog/?p=946. This still works for me, using FB 4.5. It has the advantage of keeping everything in 1 SWF file, which for distribution to portals (i do games) is important.

    The following is an example preloader. On your 'real' main class, you'd use the [Frame(factoryClass="com.example.Preloader")] meta-data to create the Preloader. You then create an instance of that main class in the onDone function of the Preloader. You use the text representation of the class name, so it doesn't get pulled into the Preloader.

    Good luck!

    package com.example.preloader
    {
        import flash.display.MovieClip;
        import flash.events.Event;
        import flash.utils.getDefinitionByName;
    
        [SWF(height="640", width="480")]
        public class Preloader extends MovieClip
        {
            public function Preloader()
            {
    
                super();
                stop();
    
                addEventListener(Event.ENTER_FRAME, doEnterFrame, false, 0, true);
    
            }
    
            private function doEnterFrame(event:Event):void
            {
    
                if(this.framesLoaded == this.totalFrames)
                {
                    removeEventListener(Event.ENTER_FRAME, doEnterFrame);
    
                    onDone();
    
                }
                else
                {
                    var percent_num:Number = Math.round((this.loaderInfo.bytesLoaded / this.loaderInfo.bytesTotal) * 100);
                    trace("--", percent_num);   
                }
            }
    
    
            private function onDone():void
            {
                trace("onDone()");
    
                this.stop();
                this.nextFrame(); 
                var rlClass:Class = getDefinitionByName("MainRobotLegsClass") as Class;
    
                addChild(new rlClass() as DisplayObject);
            }
        }
    }
    
  2. Ondina D.F. closed this discussion on 02 Feb, 2012 10:39 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac