title: ActionScript 3.0 Preloader Issues
body: <p>First off, I greatly appreciate any help, as always....</p>
  
  <p>I have created a preloader from <a href="http://www.portentinteractive.com/blog/advanced-actionscript-3-preloa.htm" rel="nofollow noreferrer">Jarrod's Advanced AS3 Preloader Tutorail</a>.  I searched elsewhere and this seemed like my best option as it was the only one I understood that did not require 2 SWF files.</p>
  
  <p>My code is really in 2 classes, my <strong>preloader</strong> class and my <strong>program</strong> class. My problem is that the preloader is only loading the graphics that are in my flash and not actually initiating the program class. My question is <em>how do I get my preloading to initiate the program class?</em> The full code for both files are below.</p>
  
  <p><strong>Preloader.as</strong></p>
  
  <pre><code>package {
      import flash.display.*;
      import flash.text.*;
      import flash.events.*;
      import fl.containers.ScrollPane;
      import flash.filters.*;
  
      public class Preloader extends MovieClip {
          public static  const ENTRY_FRAME:Number=3;
          public static  const DOCUMENT_CLASS:String='Program';
          public var myText:TextField;
          public var myFormat:TextFormat;
          private var progressBar:Sprite;
          private var progressText:TextField;
          public function Preloader() {
  
              stop();
              progressBar = getChildByName("loadbar_mc") as Sprite;
              progressText = getChildByName("loading_txt") as TextField;
  
              progressBar.scaleX = 0;
  
              myFormat = new TextFormat();
              myFormat.font="Helvetica";
              myFormat.color = 0x000000;
              myFormat.size = 24;
  
  
  
              loaderInfo.addEventListener(Event.INIT, initHandler);
              loaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
              loaderInfo.addEventListener(Event.COMPLETE, completeHandler);
              loaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
          }
          private function initHandler(event:Event):void {
              progressBar.scaleX = 0;
              progressText.text = "Loading 0%";
  
          }
          private function progressHandler(event:ProgressEvent):void {
              var loaded:uint = event.bytesLoaded;
              var total:uint = event.bytesTotal;
  
              var percentLoaded:Number = Math.round((loaded/total) * 50);
              progressBar.scaleX = loaded/total;
              progressText.text = "Loading " + percentLoaded + "%";
  
          }
          private function completeHandler(event:Event):void {
              play();
              addEventListener(Event.ENTER_FRAME, enterFrameHandler);
  
          }
          private function enterFrameHandler(event:Event):void {
              if (currentFrame &gt;= Preloader.ENTRY_FRAME) {
                  removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
                  stop();
                  main();
  
              }
  
  
          }
          private function errorHandler(event:IOErrorEvent):void {
              myText.text = ("Sorry, there was an error. " + event);
              myText.setTextFormat(myFormat);
  
  
          }
          private function main():void {
  
              var programClass:Class = loaderInfo.applicationDomain.getDefinition(Preloader.DOCUMENT_CLASS) as Class;
              var program:Sprite = new programClass() as Sprite;
  
              addChild(program);
  
  
          }
  
      }
  }
  </code></pre>
  
  <p><strong>Program.as</strong></p>
  
  <pre><code>package {
      import flash.display.*;
      import flash.events.*;
      import flash.filters.*;
      import flash.text.*;
      import fl.controls.TextInput;
      import fl.transitions.Tween;
      import fl.transitions.easing.*;
      import fl.containers.ScrollPane;
      import flash.geom.Rectangle;
      import fl.controls.Label;
  
  
  
      public class Program extends Sprite {
          public function Program() {
              //define variable
              var startX:Number;
              var startY:Number;
              var counter:Number = 0;
              var intMessages:Number = 550;
              var limit:Number = 10;
              var intBoardSize:Number = 476*(Math.round(intMessages/15)+1);
              var intMessageMinX:Number = 35;
              var intMessageMaxX:Number = intBoardSize-99;
              var intMessageMinY:Number = 50;
              var intMessageMaxY:Number = 310;
              var activeGloveName:String = ""
              var intDegreeHigh:Number = 45;
              var intDegreeLow:Number = -45;
              var newGlove:mcGlove;
  
              //create objects
              var myGlove:mcGlove = new mcGlove();
              var showGlove:mcGlove = new mcGlove
              var mcglovetarget:mcGloveTarget = new mcGloveTarget();
              var myDropShadowFilterSmall = new DropShadowFilter (2,45,0x000000,0.65,3,3,2,3,false,false,false);
              var myDropShadowFilterDown = new DropShadowFilter (3,45,0x000000,0.65,5,5,2,3,false,false,false);
              var myDropShadowFilterUp = new DropShadowFilter (5,45,0x000000,0.65,7,7,2,3,false,false,false);
              var topShadow = new DropShadowFilter (3,90,0x000000,0.35,8,8,2,3,false,false,false);
              var pinkline:Sprite = new Sprite();
              var searchBox:Sprite = new Sprite();
              var txtSearchBox:TextInput = new TextInput();
              var sSearchBox_Label:String = "Go to glove #";
              var messageFormat:TextFormat = new TextFormat();
              var messageTextField:Label = new Label();
              var searchBoxLFormat:TextFormat = new TextFormat();
              var txtSearchBox_Label:TextField = new TextField();
              var SearchBoxBg:Sprite = new Sprite();
              var topShadowBox:Sprite = new Sprite();
              var searchButton:searchBtn = new searchBtn();
              var alertRect:Rectangle = new Rectangle(0,0,848,393);
              var errorMessage:AlertBox = new AlertBox(alertRect);
              var holder:MovieClip = new MovieClip();
              var aMessages:Array = new Array();
  
              //Create a glove for each message
              for (var gloveCount = 0; gloveCount &lt; intMessages; gloveCount++){
                  aMessages[gloveCount] = new mcGlove();
                  aMessages[gloveCount] = createMessage(aMessages[gloveCount], gloveCount, gloveCount);
              }
  
  
              var scrollPane:ScrollPane = new ScrollPane();
              scrollPane.verticalScrollPolicy = "false";
              scrollPane.move(374, 0);
              scrollPane.setSize(476, 370);
              scrollPane.horizontalLineScrollSize = 120;
  
              topShadowBox.graphics.beginFill(0x333333);
              topShadowBox.graphics.drawRect(0,0,870,5);
              topShadowBox.x = -10;
              topShadowBox.y = -5;
              topShadowBox.filters = [topShadow];
  
              pinkline.graphics.beginFill(0xDB9195);
              pinkline.graphics.drawRect(0,0,476,2);
              pinkline.x = 374;
              pinkline.y = 353;
  
              searchBox.graphics.beginFill(0xDB9195);
              searchBox.graphics.drawRect(0,0,476,25);
              searchBox.x = 374;
              searchBox.y = 370;
  
              SearchBoxBg.graphics.beginFill(0xffffff);
              SearchBoxBg.graphics.drawRect(0,0,35,17);
              SearchBoxBg.x = 475;
              SearchBoxBg.y = 374;
  
              txtSearchBox.width = 35;
              txtSearchBox.height = 15;
              txtSearchBox.move(475,375);
              txtSearchBox.restrict = "0-9";
              txtSearchBox.maxChars = 4;
              //txtSearchBox.background = "0xffffff";
              //txtSearchBox.border = "0x0xDB9195";
  
              searchBoxLFormat.font="Helvetica";
              searchBoxLFormat.color = 0xffffff;
              searchBoxLFormat.bold = true;
              searchBoxLFormat.size = 10;
  
              txtSearchBox_Label.x = 400;
              txtSearchBox_Label.y = 374;
              txtSearchBox_Label.width = 70;
              txtSearchBox_Label.height = 17;
              txtSearchBox_Label.text = sSearchBox_Label;
              txtSearchBox_Label.setTextFormat(searchBoxLFormat);
  
              searchButton.x = 534;
              searchButton.y = 382;
  
              //add to frame
              sortObjects();
  
              scrollPane.source = holder;         
  
              //create instance names for referancing/compairing objects
              myGlove.name = "mcglove";
              myGlove.setGloveMessage("My Sister Suzy, I pray that she will be ok. I love here so much, she is the best sister ever.  I miss you RIP");
              mcglovetarget.name = "mcglovetarget";
  
              messageFormat.font="Helvetica";
              messageFormat.color = 0xffffff;
              messageFormat.bold = true;
              messageFormat.size = 17;
              messageFormat.align = "center";
  
              messageTextField.x = -85;
              messageTextField.y = -40;
              messageTextField.width = 135;
              messageTextField.height = 140;
              messageTextField.text = myGlove.getGloveMessage();
              messageTextField.wordWrap = true;
              messageTextField.mouseEnabled = false;
              messageTextField.buttonMode = true;
              messageTextField.setStyle("textFormat", messageFormat);
              //messageTextField.hitArea = 0;
              myGlove.addChild(messageTextField);         
  
              //position the glove and modify apperiance
              myGlove.x = 163;
              myGlove.y = 211;
              myGlove.filters = [myDropShadowFilterDown];
              //myGlove.addChild(messageTextField);
              showGlove.x = 163;
              showGlove.y = 211;
              showGlove.filters = [myDropShadowFilterDown];
              mcglovetarget.x = 615;
              mcglovetarget.y = 211;
              mcglovetarget.alpha = 0
  
              //action listeners
              myGlove.addEventListener(MouseEvent.MOUSE_DOWN, selectGlove);
              myGlove.addEventListener(MouseEvent.MOUSE_UP, releaseGlove);
              searchButton.addEventListener(MouseEvent.CLICK, searchMessages);
              txtSearchBox.addEventListener(KeyboardEvent.KEY_UP, checkForEnter);
  
  
              function selectGlove(event:MouseEvent):void {
                  event.currentTarget.startDrag(true);
                  var myTargetName:String = event.currentTarget.name + "target";
                  var myTarget:DisplayObject = getChildByName(myTargetName);
                  myGlove.filters = [myDropShadowFilterUp];
                  addChild(myTarget);
                  event.currentTarget.parent.addChild(event.currentTarget);
                  addChild(topShadowBox);
                  myTarget.alpha = .5;
                  startX = event.currentTarget.x;
                  startY = event.currentTarget.y;
              }
  
              function releaseGlove(event:MouseEvent):void {
                  event.currentTarget.stopDrag();
                  var myTargetName:String = event.currentTarget.name + "target";
                  var myTarget:DisplayObject = getChildByName(myTargetName);
                  event.currentTarget.filters = [myDropShadowFilterDown];
                  myTarget.alpha = 0;
  
                  if (event.currentTarget.dropTarget != null &amp;&amp; event.currentTarget.dropTarget.parent == myTarget){
                      event.currentTarget.removeEventListener(MouseEvent.MOUSE_DOWN, selectGlove);
                      event.currentTarget.removeEventListener(MouseEvent.MOUSE_UP, releaseGlove);
                      event.currentTarget.x = myTarget.x;
                      event.currentTarget.y = myTarget.y;
                      var myTween:Tween = new Tween(getChildByName(event.currentTarget.name), "scaleX",Strong.easeOut,getChildByName(event.currentTarget.name).scaleX,.28,2,true);
                      var myTween2:Tween = new Tween(getChildByName(event.currentTarget.name), "scaleY",Strong.easeOut,getChildByName(event.currentTarget.name).scaleY,.28,2,true);
                      holder.addChild(getChildByName(event.currentTarget.name));
                      event.currentTarget.removeChild(messageTextField);
                      scrollPane.source = holder;
                      holder.getChildByName(event.currentTarget.name).x=Math.round(Math.random() * (470+Math.round(scrollPane.horizontalScrollPosition) - Math.round(scrollPane.horizontalScrollPosition))) + Math.round(scrollPane.horizontalScrollPosition);
                      holder.getChildByName(event.currentTarget.name).y=Math.round(Math.random() * (intMessageMaxY - intMessageMinY)) + intMessageMinY;
                      holder.getChildByName(event.currentTarget.name).addEventListener(MouseEvent.MOUSE_DOWN, clickMessage);
                      holder.getChildByName(event.currentTarget.name).addEventListener(MouseEvent.MOUSE_UP, releaseMessage);
                      event.currentTarget.name = "" + intMessages;
                      addChild(showGlove);
                      messageTextField.text = "Select a glove to view its message here.";
                      showGlove.addChild(messageTextField);
                  } else {
                      event.currentTarget.x = startX;
                      event.currentTarget.y = startY;
                  }
  
                  //sortObjects();
                  addChild(mcglovetarget);
                  addChild(scrollPane);
                  addChild(pinkline);
                  addChild(searchBox);
                  addChild(SearchBoxBg);
                  addChild(txtSearchBox);
                  addChild(txtSearchBox_Label);
                  addChild(searchButton);
                  addChild(topShadowBox);
              }
  
              function position(target) {
                  target.x = Math.round(Math.random() * (intMessageMaxX - intMessageMinX)) + intMessageMinX;
                  target.y = Math.round(Math.random() * (intMessageMaxY - intMessageMinY)) + intMessageMinY;
                  for (var i:uint=0; i&lt;aMessages.length -1 ; i++) {
                      if(target.hitTestObject(aMessages[i]) &amp;&amp; counter &lt; limit){
                          counter++;
                          position(target);
                          //return false;
                      };
                  }
              } 
  
              function createMessage(newGlove:mcGlove, sName:String, sMessage:String){
                  newGlove.scaleX = .28;
                  newGlove.scaleY = .28;
                  counter = 0;
                  position(newGlove);
                  newGlove.rotation = (0, 0, 0, Math.round(Math.random() * (intDegreeHigh - intDegreeLow)) + intDegreeLow);
                  newGlove.filters = [myDropShadowFilterSmall];
                  newGlove.name = sName;
                  holder.addChild(newGlove);
                  newGlove.setGloveMessage(sMessage);
                  newGlove.addEventListener(MouseEvent.MOUSE_DOWN, clickMessage);
                  newGlove.addEventListener(MouseEvent.MOUSE_UP, releaseMessage);
                  newGlove.buttonMode = true;
                  return newGlove;
              }
  
              function clickMessage(event:MouseEvent):void{
                  selectMessage(event.target);
              }
  
              function checkForEnter(event:KeyboardEvent):void
              {
                  if (event.keyCode == 13) // If Keypress is Enter
                  {
                      searchMessages();
                  }
              }
  
  
              function searchMessages():void{
                  if (showGlove.parent == mcglovetarget.parent){
                      if ( txtSearchBox.text != "" ){
                          var searchTarget:DisplayObject = holder.getChildByName(txtSearchBox.text);
                          if (searchTarget){
                              selectMessage(searchTarget);
                              scrollPane.horizontalScrollPosition = searchTarget.x - 220;
                          }else if(1==1){ //if in file
                              gloveCount = aMessages.length;
                              aMessages[gloveCount] = new mcGlove();
                              aMessages[gloveCount] = createMessage(aMessages[gloveCount], txtSearchBox.text, txtSearchBox.text);
                              selectMessage(aMessages[gloveCount]);
                              scrollPane.horizontalScrollPosition = aMessages[gloveCount].x - 220;
                          }else{
                              errorMessage.setAlertText("Sorry, the glove you are searching for does not exist.");
                              addChild(errorMessage);
                          }
                      }
                  }else{
                      errorMessage.setAlertText("You must post your message first, otherwise your message will be lost.");
                      addChild(errorMessage);
                  }
              }
  
              function selectMessage(object:mcGlove):void{
                  if (showGlove.parent == mcglovetarget.parent){
                      if (activeGloveName != ""){
                          var activeGlove:DisplayObject = holder.getChildByName(activeGloveName);
                          activeGlove.filters = [myDropShadowFilterSmall];
                          activeGlove.scaleX = .28;
                          activeGlove.scaleY = .28;
                          holder.addChild(activeGlove);
                      }
                      activeGloveName = object.name;
                      //event.target.dragIt();
                      holder.addChild(object);
                      object.filters = [new GlowFilter(0xABEEFC, .65, 15, 15, 1, 1, false, false)];
                      object.scaleX = .35;
                      object.scaleY = .35;
                      messageTextField.text = object.getGloveMessage();
                  }else{
                      errorMessage.setAlertText("You must post your message first, otherwise your message will be lost.");
                      addChild(errorMessage);
                  }
              }
  
              function releaseMessage(event:MouseEvent):void{
                  event.target.dropIt();
              }
  
  
  
              function sortObjects():void{
                  addChild(mcglovetarget);
                  addChild(scrollPane);
                  addChild(pinkline);
                  addChild(searchBox);
                  addChild(SearchBoxBg);
                  addChild(txtSearchBox);
                  addChild(txtSearchBox_Label);
                  addChild(searchButton);
                  addChild(myGlove);
                  addChild(topShadowBox);
              }
  
              myGlove.buttonMode = true;
              searchButton.buttonMode = true;
  
          }
      }
  }
  </code></pre>