tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/763-methedology-preloading-robotlegs-appRobotlegs: Discussion 2018-10-18T16:35:35Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/124645302011-12-28T20:56:18Z2011-12-29T17:55:16ZMethedology: Preloading Robotlegs App<div><p>Hello,</p>
<p>I've completed an app using the Robotlegs Framework as a flash
professional project in Flash Builder 4.6.<br>
All is working great! and my app is completed.</p>
<p>However, due to it's size I want to use a preloader swf to load
in the main app.</p>
<p>Question: What is the best approach for this?</p>
<p>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</p>
<p><a href=
"http://knowledge.robotlegs.org/discussions/problems/270-using-a-preloaderfla-seems-to-be-screwing-up-my-injection">
http://knowledge.robotlegs.org/discussions/problems/270-using-a-pre...</a></p>
<p>But after following the fixes and critiques in the post I now
find myself a little lost on how this should be implemented.</p>
<p>Can somebody lend me some wisdom on what is the best approach to
preloading a robotlegs app.</p>
<p>Thanks!</p></div>Johntag:robotlegs.tenderapp.com,2009-10-18:Comment/124645302011-12-30T15:25:41Z2011-12-30T15:25:42ZMethedology: Preloading Robotlegs App<div><p>I personally use the
<code>[Frame(factoryClass="com.example.Preloader")]</code>
meta-data, following the example here: <a href=
"http://www.bit-101.com/blog/?p=946">http://www.bit-101.com/blog/?p=946</a>.
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.</p>
<p>The following is an example preloader. On your 'real' main
class, you'd use the
<code>[Frame(factoryClass="com.example.Preloader")]</code>
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.</p>
<p>Good luck!</p>
<pre>
<code>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);
}
}
}</code>
</pre></div>Jos