Create a generic preloader in Actionscript 3.0

Monday, June 16, 2008

It might seem an obvious topic is exhausted, yet with Flash CS3 and the new management of the document class (package) permitted in Actionscript 3.0, it is not entirely immediate create a preloader working. The latest release of Flash, in fact, manages the loading of the movie so different from previous versions. On the web you can find different proposals and solutions to create a preloader "old fashioned". However, the various examples that I found I did not fully meet as they require to alter the movie so that it works as a preloader classic. In practice, when you develop you should always remember "this thing I must do that otherwise the preload does not work! And for movies that are filled in, then?

Loader

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

Security: swf and images

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

For more information on this subject see Security and LoaderContext

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

1. Swf file name to upload

To make a generic loader is obvious that the name of the movie (as any other information: title, ...) should be passed in some way runtime. The technique I used is that described in Reading the parameters of a movie in Actionscript 3.0. In practice we would have:

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

2. Dimensions

Setting the stage loader mode StageScaleMode.NO_SCALE you can set the loader movie at 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. frameRate = _loader . contentLoaderInfo . frameRate ; Stage. frameRate = _loader. contentLoaderInfo. frameRate;

Sources

An example of a class loader is UndoLoader.as. This can be used as a document class in a movie (loader.fla), which will contain the graphic elements (complex as you want) of your preloader.

Related Post

Was this article helpful?: Per nientePocoAbbastanzaMoltoMoltissimo
Loading ... Loading ...

10 comments to "Creating a generic preloader in Actionscript 3.0"

  1. getAvatar 1.0
    03 lug, 2008 Marcos:

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

    valeu

  2. getAvatar 1.0
    03 ago, 2008 Peno:

    The files you download do not work, and an explanation of how to invoke the external file is not at all clear, "loader.swf? Filename = filmato.swf" because in the article "Reading the parameters of a movie in Actionscript 3.0" uses html code??? you could clarify this point? thanks.

  3. getAvatar 1.0
    04 ago, 2008 Giovambattista Fazioli:

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

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

    1) Use an HTML directly
    2) Use your own Javascriopt function that inserts the code dynamically
    3) Use tools like lightWindow or Shadowbox
    4) Use tools like SWFObject

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

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

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

  4. getAvatar 1.0
    04 ago, 2008 Peno:

    Thanks for your answer, but given my ignorance on the subject do not understand how to load an external SWF file just using flash, to understand not know what to change UndoLoader.as.
    the file. fla to download it when I try to publish it tells me it is impossible to check whether there is a disc stuck in writing! which is not!
    Thanks
    Peno.

  5. getAvatar 1.0
    04 ago, 2008 Giovambattista Fazioli:

    @ Peno: class Undoloader.as do not need to change it, at least you do not need to make it all work. The main issue is that the class Undoloader.as be linked to a Flash movie clip, what you've downloaded as an example. To make everything work, you must:

    1) Create a folder and this is the place. FLA class Undoloader.as
    2) Open. FLA and check the settings of publication, it is these that will probably cause some problems

    The movie thus established becomes the "load" of what? Of what steps in the "MIME" when you include it in your page.

    If you give me a valid email address (the one you entered returns me back) I write to you in person in more detail.

  6. getAvatar 1.0
    04 ago, 2008 Peno:

    thanks for the availability, this email safe operation
    peno78@gmail.com.

    Peno.

  7. getAvatar 1.0
    07 giu, 2009 Matthias:

    Similar problem:

    Once you download the fla and class, when I try to export the Flash movie tells me:

    "Error while creating the swf file.
    Make sure the destination file is not locked or located in a drive stalled. Also verify that the file name is too long. "

  8. getAvatar 1.0
    07 giu, 2009 Giovambattista Fazioli:

    @ Matthias: As I said in "Peno", check the publishing settings of the movie.

  9. getAvatar 1.0
    07 feb, 2010 MB curious:

    I gives me a warning of "Packages can not be nested"

  10. getAvatar 1.0
    07 feb, 2010 Giovambattista Fazioli:

    MB @ curious: strange ... control of non-loaded two sizes the same package

Leave a comment

TAG XHTML PERMISSIONS: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> INSERTION CODE:
 <pre></pre>         // blocco generico [code][/code]       // blocco generico [as][/as]           // Actionscript [css][/css]         // CSS Style Sheet [html][/html]       // HTML [js][/js]           // Javascript [objc][/objc]       // Objective-C [php][/php]         // PHP [sql][/sql]         // SQL