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-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