1
votes

I need to add a preloader / splash screen to an Adobe Air application that I am building in IntelliJ Idea using pure Actionscript.

I have found many solutions, but they all assume a flex application. I am using the flex compiler, but the project is not written in flex so there are no mxml tags in order to use SparkMobileSplashScreen.mxml

Can a splash screen image be added to the air application xml file somehow?

1

1 Answers

1
votes

Here's a basic setup for an embedded preloader. Your Document Class should look like this:

package {

  import flash.display.Sprite;

  [Frame(factoryClass='Preloader')] //class name of your preloader

  public class Main extends Sprite {

     public function Main() {
        //init
         }
      }
    }

Preloader Class:

package {

import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.events.ProgressEvent;
import flash.utils.getDefinitionByName;

public class Preloader extends MovieClip {

 public function Preloader()
 {
    //add preloader graphics 

    //check loading progress
    this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
 }
 private function onProgress(e:ProgressEvent):void 
 {
    var percent:Number = Math.round(e.bytesLoaded / e.bytesTotal * 100);
    if (percent == 100)
    {
      this.loaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgress);
      onLoaded();
    }
 }
 private function onLoaded():void
 {
   nextFrame(); //go to next frame
   var App:Class = getDefinitionByName("Main") as Class; //class of your app
   addChild(new App() as DisplayObject);
  }
 }
}