Preloader in as3 using preloader sample provided in cs5 - actionscript-3

I am working on a project in which i want to add preloader and for that i have used the sample preloader provided in cs5 (in sample files). i have moved(from another fla) all my code to second frame and all library content to current fla's library.
Now the problem is that the size of first frame is now 182kb (the size of library content)
which is only 8kb when i have not added my library content in current fla's library.
And due to this when i test the movie the first frame(preloader) is not shown up until the 182 kb is loaded and immediately after that second frame is shown up.
here my question is how can i load library contents in second frame ?
i am having a large number of library content which is expected to increase in future.
here are two snapshot:
the library:
testing the movie:
you can see in second snapshot the size of first frame is 182kb.
Please provide a good solution for this problem.
Thanks !

Assets which have not linkage load until the frame they first appear, so if you move all your assets to the second (or later) frame, you could have code in the first frame that executes before all the other assets (in frame two or later) finish loading.

You could create your preloader in another fla. This new fla's only job would be to load/preload your main fla, so your preloader's fla size would be very small.
In such case, you wouldn't have to move your library content to the second frame of your main fla, quite the opposite actually.

Related

Flash / pure AS3 preloader is seen after game is 100% loaded

first of all I want to tell that I know there are hundreds of similar questions, but most of them are for projects/games which are built for "on stage development".
I'm using pure as3 approach to develop games. I don't use*main timeline and my project has only 1 frame*.
On my main class's constructor, I only add preloader to the stage.
But still my preloader is seen only when the game is completely loaded.
My question is simple: "Why?" and "How can I fix this?"
-When I try to "uncheck" export as3 on frame 1, flash gives error.(because some of my classes are imported on the main class.)
-Even if I create second frame and put every contents of the game except preloader, the problem is still unsolved.
Thank you very much for spending your time to read this and help me.
-Ozan
To make the preloader, you either need two SWFs or at least two frames. Even FlashDevelop has an ability to use two frames, for this the directive [frame factoryClass="ClassName"] is used in main AS file before public class Main. This is the core limitation of Flash player, that is, it first loads the first frame, and only then it can display that frame. Since you've said you have only one frame, then your game has to be loaded 100% (1/1 frames) before you will see a thing.
There's more - if you are referencing a certain class on frame 1 via its class name, the class with all its dependencies is embedded in the same frame (the first), so you're screwed again. To bypass this, execute stepos 10 through 14 from this instruction to set the frame for classes to be 2 (replace 10 for 2 while executing the instruction), clear "export in the first frame" for all classes except your preloader, and add an instance of game's main class to keyframe 2. Then in preloader code perform proper cleanup and do gotoAndStop(2).

Only the loader images are being exported in frame 1 but the loader still only shows up at 100%

As the title says, the file loads correctly but the loading screen only flashes up at the end.
The only thing being exported in frame 1 is the loader image, and that is extremely small.
Is it possible that there's a queue of things being loaded and the loader image is at the bottom of that queue? Since that was one of the last things added to the project
If your preloader only shows up after the file has loaded, this means that you still have other objects being linked onto Frame 1. Flash is very picky about this, and it's easy for things to be yanked onto Frame 1 regardless of your settings. When you compile, Flash builds a dependency graph to determine what items are needed on each frame. If it thinks an asset is needed earlier than the export frame setting, it will ignore the setting and push the asset onto that frame. In particular, any class that your document class directly references will be automatically yanked onto frame 1.
Checking "Generate size report" in File, Publish Settings, Flash can help you see how much data is being exported onto Frame 1. Here are some tips to ensure that everything is linked onto the proper frame:
In Publish Settings, Flash, ActionScript Settings, make sure that "Export frame for classes" is set to 2 or higher.
Ensure that library symbols say "Export on frame 2" in their linkage properties. Older versions of Flash may export them on frame 1, regardless of the class export frame. In this case, you'll have to do the oldschool method of unchecking the "Export on frame 1" option, and manually dragging these symbols onto the timeline on frame 2.
Do not directly reference classes from your document class or on the main timeline. The Document class and all the assets it references are always placed on frame 1. Anytime you do var f : MyClass; in your document class or on the root timeline, then you are referencing MyClass, and Flash will automatically yank it onto frame 1.
To avoid directly referencing your main app class in your preloader, you want to instantiate it indirectly, using something like this:
var gameClass : Class = flash.utils.getDefinitionByName("Game") as Class;
var game : Sprite = new gameClass();
In this case, your Preloader becomes the document class, and indirectly creates the Game class when the SWF has loaded. This avoids any direct references to Game and its content.

AS3: Preloader Not Working w/ Exported for AS Graphics

I have a lot of graphics and sounds in my library that are exported for Actionscript in Frame 1. I believe that because of the exported graphics, my preloader will not work. All I get is a white frame while the movie loads.
How can you preload graphics that are exported for Actionscript?
When you export for Actionscript in Frame 1, everything that is exported must be loaded before any content is visible. I usually uncheck this button, and then everything is exported to the first frame where it's referenced. For more details on this approach, check out http://www.developria.com/2010/04/combining-the-timeline-with-oo.html . Howwever, if you're like most developers, you probably reference everything from your main document Class, so this may not do you much good. It does offer the possibility that you can avoid a preloader altogether, though, because loading is spread across different frames.
If your movie is structured like normal, check out http://www.8bitrocket.com/2008/4/22/Tutorial-Preloading-Actionscript-3-AS3-Games-in-Flash-CS3/ .
It is not applicable on every case, but maybe you can preloader in separate file, which loads your main swf.
You can see detailed how to in this tutorial: http://www.gotoandlearn.com/play.php?id=85

Adding a Preloader in CS5 as3 project

I am Working on a cs5 as3 project and in that project i have writen all code in the frame1 of main timeline (there is no package/class in the code)
The code in the main timeline is very complex in which i am loading external images and xml's and many more things .
i have not written any code in the action layer.
Now i want to add Preloader .
how can i add Preloader in this situation ?
here is a snapshot of the timeline :
Move everything to the second frame, and add your preloader code/content on the first frame
http://www.google.ca/search?q=preloader+code+as3
The real issue here is the number and size of external assets you're loading, it may have been worth considering loading some of these assets separately. In this way, your preloader would have been more accurate. However complex your code is , the loading of the assets is the main element to delay the start of your application.
With your current configuration , if you'd encapsulate the loading of some of the assets (as you may not need all of them right from the start) , you would have been able to directly create a preloader within the code as is , without a DocumentClass, simply by loading assets as your first function and calling an init() method after the loading is complete.

AS3 preloader sorrows, unable to load symbols from library

I created an AS3 preloader, and placed the code for that on frame one.
I then made a symbol, and placed it in the library. It was set to NOT export on frame 1, and the fla's settings had all classes exported on frame two. There were no references to the object until frame two.
Then, flash crashed whenever I compiled without the "Export in frame one" box checked.
To fix this, a friend suggested I start my game logic on frame 3, so it will have properly loaded frame 2. That seemed to work fine, the class was instantiating properly.
Then, it turned out that it was not loading the movieclip, only instantiating the class. Again, this could be fixed by exporting in frame 1, but I really cannot afford to do that.
The same friend suggested I place an instance of the symbol on the stage on frame 3, and perform game logic on frame 4. They said this would initialize the movieclip properly.
However, this was not the case. How can I load the entire symbol, graphics and all, without exporting to frame 1? This single symbol will contain probably 10-20 MB of graphics, so it needs to be preloaded.
Thanks for the help!
EDIT: To make a long story short, all I need is some way to load a movieclip so it can be used and visible and everything.
EDIT: Is there any way to force-load a movieclip via AS3?
Hard to figure out from descriptions.
If you make a new .fla file, paste your large(10-20MB) clip on frame 2,
set your export frame as 2, then try to preload from frame 1 and access the large clip's content in frame 2, do you get the same error ?
say you have this in frame 1:
stop();
this.loaderInfo.addEventListener(Event.COMPLETE, onComplete);
function onComplete(event:Event):void{
gotoAndStop(2);
}
and in frame 2:
trace(myLargeClip);//where myLargeClip would be your 10-20MB clip
It should be ok, otherwise, in case tracing your large clip returns null, you might want to try to invalidate the stage:
on frame 2:
stage.addEventListener(Event.RENDER,onRender);
stage.invalidate();
function onRender(event:Event):void{
trace(myLargeClip);
}
Basically what I'm suggesting is:
Isolate the problem. See if your large clip is causing problems in a similar, but simplified scenario and why, then once you got a fix use it in your main fla.
Try the stage invalidation, although, since I don't fully understand your setup, it's just a wild guess.
HTH,
George