• home
  • forum
  • my
  • kt
  • download
  • Preloading in AS3 w/ Exports

    Author: 2009-07-15 01:21:16 From:

    First you have to access your Publish Settings. Go into your FLA file and press CTRL+SHIFT+F12. If this doesn’t work then you can always access the Publish Settings through File -> Publish Settings.
    You should get to this window:
    Preview 1
    Now go to the Flash Tab, and you should see a button called Settings… located right next to a drop down box labeled “ActionScript 3.0″. Click on it.
    You should be at this location now:
    Preview 1
    Now look at the spot that’s labeled “Export classes in frame:”. Right next to it should be a text box that by default should be 1. Change it to 2, then click Ok.
    What this does is allow you to put a preloader in frame 1 and preload all your exports too. All the music/sounds/movie clips you add dynamically from the library will be loaded after frame 1 is loaded. So you can put your preloader in frame 1 and it’ll preload all exports.

    Next step is to create a preloader. You can’t have the preloader be a class or have a class name or else it’ll be loaded on frame 2 also and you’ll get an error.
    So create a Rectangle. Make the border, and filling a different MovieClip. Give the filling the instance name bar_mc. Then in the first frame of your project, put this code:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    addEventListener(Event.ENTER_FRAME, onEnter);

    function onEnter(e:Event):void{
        var perc:uint = new uint();
        perc = this.loaderInfo.bytesLoaded/this.loaderInfo.bytesTotal*100;
        if(perc == 100)
        {
            removeEventListener(Event.ENTER_FRAME, onEnter);
            nextFrame();
        }else{
            bar_mc.scaleX = perc/100;
        }
    }

    Now what you’ll want to do is in your main class, create a function called init(), and have all the code that happens when the project loads in there. Then in your frame 2, put:

    1
    2
    init();
    stop();

    To download the FLA, click here

    discuss this topic to forum

    relation tutorial

    No information

    Category

      3D (36)
      Math Physics (18)
      3rd Party (10)
      Navigation (70)
      Actionscripting (252)
      Optimization (17)
      Animation (185)
      Projector (11)
      Audio (54)
      Special Effects (173)
      Backend (26)
      Text Effects (93)
      Drawing (34)
      Tips and Techniques (58)
      Dynamic Content (38)
      Tricks (8)
      Games (114)
      Utilities (24)
      Getting Started (99)
      Video (59)
      Interactivity (48)
      Web Design (37)

    New

    Hot