Creating a generic preloader in Actionscript 3.0

Monday, 16 June, 2008

It might seem a foregone conclusion and argument now exhausted, but with Flash CS3 and the new document management classes (package) allowed with Actionscript 3.0, is not entirely immediate create a preloader working. The latest release of Flash, it manages to load the movie so different from previous versions. In network you can find various proposals and ways to recreating a preloader "old". However, several examples that I found I did not fully meet as required to alter the movie to make it work like a classic preloader. In practice when you develop must always remember "this what I have to do so otherwise the preload does not work!" And for movies already completed, then?

Loader

The solution I have adopted, at least for now, was to create a movie outside (my loader - see example) can upload any other movie outside, including a picture! This solution, although in practice requires two movies (the loader and FILAM real), becomes economic only if you manage to create a loader can be used over and over again, that is able to load any movie, any and any resolution frame.

Security: swf and images

Remember that if the movie swf to load is on a different domain from the loader, you'll have to deal with the security system of Flash. If you use the loader to load images, however, the problem does not exist. In class I presented there is no control over the sandbox and system security, as the loader use the same domain.

For more information on this subject see Security and LoaderContext

The class LoaderContext provides the necessary options to the loading of SWF files and other multimedia content through the Class Loader The class LoaderContext is used as a parameter in the context methods load() loadBytes() Class Loader
When loading the SWF file by the method Loader.load() you must decide what security domain in which domain and application within the domain of security you want to place them. For more information about these options, see the properties applicationDomain and securityDomain [...]

1. Name of the swf file to upload

To create a generic loader is obvious that the name of the movie (as possibly other information: Title, ...) should be passed somehow runtime. The technique I used is described in Reading the parameters of a movie in Actionscript 3.0. In fact, you will:

CODE:
  1. loader. swf? filename = movie. swf

2. Size

Setting stage stage of the loader mode StageScaleMode.NO_SCALE you can set the movie loader to the same resolution of the movie to load! That's all!

3. Frame Rate

When loading the external movie is finished simply run:

Actionscript:
  1. = _loader. contentLoaderInfo . frameRate ; stage. framerate = _loader. contentLoaderInfo. framerate;

Sources

An example of a class loader is UndoLoader.as. It can be handled as a class paper in a movie (loader.fla), which will contain graphics (complex as you want) your preloader.

Related Post

6 comments to: "Creating a generic preloader in Actionscript 3.0"

  1. getAvatar 1.0 Thursday, 03 July, 2008 at 20:00
    Marcos said:

    Eu sou novo com flash and AS, portanto fiquei com algumas Dúvidas, não um rola step by step?

    valeu

    Answer Quote
  2. getAvatar 1.0 Sunday 03 August, 2008 at 23:20
    Peno said:

    The files that you download will work, and explaining how to retrieve the external file is not clear, "loader.swf? Filename = filmato.swf" because in the article "Read the parameters of a movie in Actionscript 3.0" uses html code? you could clarify this point? thanks.

    Answer Quote
  3. getAvatar 1.0 Monday 04 August, 2008 at 10:17 a.m.
    Giovambattista Fazioli said:

    Peno @: For the parameters indicating loader.swf?filename=nomefilmatodacaricare.swf is purely technical in that it shows how to pass parameters MIME (in GET) data to the movie "shipper".

    In you mentioned use HTML code but depends on the technique that you want to use to show the movie on the page. When you add dynamic content to an HTML page, in this case a flash, you can use several methods:

    1) Use an HTML directly
    2) Use your function Javascriopt entering the code dynamically
    3) Use tools like LightWindow or Shadowbox
    4) Use tools like SWFObject

    That is why I simply stated the "pass parameters MIME": loader.swf?filename=nomefilmatodacaricare.swf

    The heart of the system, however, is the class UndoLoader.as

    The FLA file is an example of its use and to me it works ... that gives you problems?

    Answer Quote
  4. getAvatar 1.0 Monday 04 August, 2008 at 11:55 a.m.
    Peno said:

    Thanks for your answer, but because of my ignorance in the field do not understand how to upload a file using only external swf flash, so not to understand what should change in UndoLoader.as.
    the file. fla scrico that when I publish it tells me that it is impossible to control and if it is blocked on a disk write! which is not!
    Thank you
    Peno.

    Answer Quote
  5. getAvatar 1.0 Monday 04 August, 2008 at 12:03 p.m.
    Giovambattista Fazioli said:

    @ Peno: class Undoloader.as you do not have to change it, at least there is no need to change it to run everything. The main issue is that the class Undoloader.as be linked to a flash loader, what you downloaded as an example. Get it all, you must:

    1) Create a folder and enter this in both. FLA that the class Undoloader.as
    2) Open. FLA and check the settings of publication, are those that will probably cause some problems

    The movie becomes so filled the "shipper" of what? What the steps in the "MIME" when you put on your page.

    If you mail me a valid (the one you entered my return back) will personally write in more detail.

    Answer Quote
  6. getAvatar 1.0 Monday 04 August, 2008 to 12:30
    Peno said:

    grazie mille for availability, this message does certainly
    peno78@gmail.com.

    peno.

    Answer Quote

Leave a comment

TAG XHTML <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <a <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Use <pre> to enclose code