Flash CS3: Preloading stage assets & external classes – Is this a useful hack?

Here’s something i created in Flash CS3 which was supposed to be the beginnings of a new AS3 website. During development i encountered some problems preloading external classes exported after frame 1. Unable to find a solution to fix my application i hacked out the example shown below. It works great but i would like to get some feedback from the community to see what you think. If it’s a bad way of doing things please tell me.

Download the original files here to see what i did. [UPDATED SOURCE 240908] Added comments to com.strangeloopstudios.main.Site (which is the document class) to further expain the hack.

Here is an update for Ian to illustrate how i added a button to the application. [NOT UPDATED]


26 responses to “Flash CS3: Preloading stage assets & external classes – Is this a useful hack?

  • ian

    is there a reason why you have so many frames inbetween the actions? could you not have done that in 4 frames (your site starting on the 4th)?

  • Doug

    Hi Ian

    Yes i could have used 4 frames but i do it like this so i can easily read the frame labels at a glance.

  • ian

    ahh thanks for the quick reply. i also have a question related to this file. (sorry i am using your preloader on my site that i’m designing because i have not been able to find one for AS3 only AS2) i have changed all the graphics so nothing is similar.

    My question is your Site file makes it so you can address MovieClips, which i need, but i also have some SimpleButton’s that i need to do as well. I was wondering if you would be able to tell me what to add to be able to do that.

    my .fla file is here:

    and the Site file where the document class is here:

  • ian

    the reason i want to add them as buttons instead of movieclips is because i have them change color when the mouse hovers over them, and secondly i want to have the buttons make the movie gotoAndStop and a certain frame. or is this possible with movie clips?

    you can always email me at iscofield@gmail.com
    thanks so much!!

  • ian

    well i figured it out already. but what i was trying to do was add not only movieclips to the movie on the site frames, but buttons as well. and because i could only declare movieclips in your source files, what i ended up doing was deleting the section for declaring the navigatio movie clips and changed in the publishing settings to automatically declare stage instances.
    are there any drawbacks to doing it that way, because it seems to be working fine, not only in the flash preview but on a hosted server.

    thanks again for your help

  • Doug

    Hi Ian,

    Does the preloader still work correctly for you? Can i see your example running on your server?

    Have you got any exported classes remaining or did you remove them all to fix the button problem?

    I’ve just added a custom button to my example, here’s what i did:

    To add a button to the project i drew an icon on the stage and made it a Button in the Flash IDE (via F8) with an instance name of’ ‘ian’. I added the over and press states as you would normally and then in my main Site class i added these new lines of code:

    import flash.display.SimpleButton;

    public var ian:SimpleButton

    The publish settings remained the same so i’m not automatically declaring the stage instances.

    I’ve updated the source files so you can see.

  • ian

    is the website i have it incorporated in.
    you can look at my fla/.as file here:

    but i think its working as planned. but then again i might be doing something completely different.

  • Doug

    Works for me except your fla gave me this error when published:
    1180: Call to a possibly undefined method AccessibilityProperties.

    I fixed it by importing the flash.accessibility.AccessibilityProperties; class but i couldn’t see why it was happening perhaps you know.

  • ian

    ahh thank you so much!!! i uploaded the wrong version but i wasn’t able to figure out how to fix that error message. thanks!!
    i had to copy and paste everything over into a new document to get it to work…can you tell i’m new at this?
    but overall does that preloader work as you intended it to or were you aiming for something different?

  • Doug

    You know what it’s hard to say. It seems to me it will work ok for MovieClips but for any other custom classes you might have a problem.

    I’ve updated your example so that the instance picture1 is now linked to a class. In the current state when the swf is run the picture1 instance will animate from left to right as defined in its class file picture1.as.

    Notice this linked class is currently set to export in frame 1 (everything works fine like this right?). Now because we’re putting the linked class in frame 1 the preloader doesn’t work as expected because it bloats the size of frame 1.

    We’re thinking ok lets just untick export in frame 1 and it will get placed at frame 3 your current export frame. Because it’s situated before the picture1 instance on the timeline you might think it would be ok but it’s not. I get a ‘TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::MovieClip@2e9f971 to tings.picture1’ error. This is where my example is different because it caters for linked classes.

  • ian

    so if its all exported on the first frame, won’t the first frame become bigger and bigger and the preloader will take longer to appear?

    secondly i have a general question. what is the advantage to creating a package for picture1 and then importing it vs. just writing the actionscript within the main timeline/.fla file? and i also don’t understand lines 9-14 in the picture1.as file. sorry for all the questions, but i’m just having such a hard time finding individualized help anywhere on the internet.

  • Doug

    Yes the first frame will become bigger which is what we are trying to avoid. I use linked custom classes in an effort to write better Object Oriented code. My example limits the size of frame 1 while still allowing stage instances to be linked to custom classes.

    Your code does not achieve this so far as i can see.

    To learn more about packages, linked classes and event handling (lines 9-14) i would recommend you get a decent AS3 book. My current favourite is Essential Actionscript 3 by Colin Moock.

  • ian

    thanks for the suggestion, i’ve bought the book and started reading, it’s very helpful and indepth.

    so as of right now, is there a way for to have the custom classes without expanding the first frame?
    some suggestions (probably stupid but…)
    1. import the class on the desired frame in actionscript in the main timeline.
    2. use the addchild method in the document class
    3. or possibly redesign the preloader (hopefully not)

    are any of those logical/possible? just thoughts

  • Doug

    Yes export all your classes to a frame after the preloader.

    You have to be careful not to reference any custom classes from your main document class ‘Site’. If you do they will automatically get exported in frame 1 regardless of your export settings because the document class needs to be able to reference them.

    My document class ‘Site’ does reference a custom class ‘Nav’ which then references all the other custom classes ‘NavIcons’, ‘Icon’. Because of this Flash tries to export all the classes in frame 1. So to get around this problem i type Nav as a MovieClip (which Nav already inherits from and which is also a dynamic class – so no problems when Flash sees new properties and methods on this particular instance)

    If you change this line in my Site class:

    public var nav:MovieClip;


    public var nav:Nav;

    See what happens. That’s why i asked is this a hack and want to find out if there are any potential problems.

  • Tink

    I find the best way to preload is to make a new FLA and load the main site into that.

  • Doug

    Hi Tink,

    I agree that in most cases i would do the same. Do you see any potential problems in my example that i may have overlooked?

  • Tink

    Not problems, just things i try to avoid.

    1. you have to place items to be exported on to the stage.
    2. i like to keep my root a single frame.
    3. you have to change the ‘export of frame’ checkbox on all your items.

  • Doug

    I like the ‘export to frame’ shortcut but often a lot of my stuff contains custom components (i’m already in the component definition window) so ticking a box usually doesn’t require too much extra effort.

    Specifically for this example i wanted to be able to place my assets on the stage in advance so i could get a feel of the layout. I assume you’re doing the same but just within the loaded swf rather than the main container.

    Do you always export to frame 1 in your loaded swf when using this type of setup?

  • Brandon

    Hi, I got a question here:

    I’m completely new to flash btw,

    I’m trying to use a graphic as a button that will link to another frame in ActionScript 3.0.

    Here is my code:

    import flash.events.MouseEvent;
    function doClick(e:MouseEvent):void

    But when I test my movie, I get this error:

    TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::SimpleButton@1c4ce7b1 to flash.display.MovieClip.
    at flash.display::Sprite/constructChildren()
    at flash.display::Sprite()
    at flash.display::MovieClip()

    What am I doing wrong?


  • Walmik

    Thanks a lot! This has been absolutely helpful. Though I get errors in the frame where I ve put the library items (export frame) – “ArgumentError: Error #1063: Argument count mismatch…”

    The error doesnt really bother the functionality of the app but it d be nice if it didnt throw an error there. These are library items that have a class and when I paste them on stage, they are not initialized with the requisite arguments…

  • Walmik

    Ah… sorry to post again… I m not getting the error any more!

    I just pushed the ‘export’ labeled frame to one frame after the frame with all the to-be-exported library items 🙂

  • Ballebrokk

    Brandon !
    Put this in your code

    import flash.display.SimpleButton

    you should also probably include this line,

    import flash.display.*

    for all the display classes. I advise reading up on it


  • Aaron

    Thanks a ton! I used your preload for my current and first flash project. Just need to put the final touches on it…


  • vinay

    Hai I have a doubt.How can we preload the external swfs The swfs appear when a button is clicked That is there should be only one preloader for every of the swfs which is listening for that click
    Thanks for your time…

  • KsElement

    Hey, I too was having this concern and I like the way you did things.

    Since you created this back in 2007, have their been any advances to the best way to load in classes?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: