AS3 - How to handle assets during preload - actionscript-3

I'm having some difficulties with preloader and assets.
I'm working with FlashDevelop so pure AS3/Flex, no FLASH IDE
The thing is : when I try to addChild() something like a swf or event a simple png/jpg it kills the preloader completly (blanck screen until the game is fully loaded, then the preloader is launch (but the game is already loaded) so one frame later I'm after the preloader.
I think I missed something in the logic behind the management of the famous "first frame" and the loader progress event.
If someone have any idea about what I'm talking about. I'd like some light about the subject ^^
Thx !
-UPDATE-
I re-searched for more informations and found this post :
How does the preloader work in as3?
MichaelJW points my problem but doesn't answer it :
"You can do whatever you like in a preloader, but it won't run any of its code until everything needed by the preloader has downloaded. So if you make a preloader with a 3MB image file and a progress bar, the progress bar won't do anything until the entire image has downloaded!"
So how do you get to use some image to build a preloader ?

I have encountered this before and my "work around" was to build 2 separate loaders. The first is VERY light weight and loads all initial assets (like a rotating 5k png), the second if the "bulk load" of assets etc..
when the first is done loading it triggers the load of the second round of assets. You are right tho, you CANNOT use assets till they are loaded completely..

Related

FirefoxOS packaged game loading time

We are working on a packaged html5 game for the FirefoxOS marketplace.
Our game passes review, except the game shows a black screen before starting. The reviewers said this black screen shows for a very long time. It is my belief that the games wrapper is trying to load ALL assets before it shows the game.
The problem is, our game already has internal loaders that load portions of the game assets. Does anybody know how to tell the FirefoxOS packaged html5 app to let the game do all of the loading, so my preloaders can work?
I also use Flambe. Befor it can display anything, it should load at least the index.html, flambe.js (flambe project loader) and ofcourse main-html.js file (actual game code). From that point you could load other assets to display an actual preloader, but that could also take time. If you use FillSprites then it reduces some time.
But what I mostly do, is adding a simple CSS3 animation (loader) on top of the canvas. I give this html element a certain id, and when I have loaded enough to show the "real" preloader, I remove this CSS loader animation from the DOM. This allows to show a preloader very fast or to load a bit more designed preloader if you wish.

Player changes size after external SWF is just loaded (but not used)

I have a flash player I am working on (developing in AS3).
The stage (and player) size are 640x979.
At the bottom of the player I have a control-bar, with play-pause buttons etc.
Here is an image of the player (image).
So far so good.
Now - on most external SWFs that I load - they load OK.
But on some - if I try to load them using the Loader class - the player goes crazy !
The control bar dissappears, and the video is stretched in a funky way. You can see this in the attached image (image).
What is really strange here is - this happens even if I don't add the Loader object as a child !
I just do this :
public function PlayerCtor()
{
swfUrlLoader = new Loader();
swfUrlLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onSwfReceived);
swfUrlLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onSwfIOError);
swfUrlLoader.load(new URLRequest(swfUrl));
}
private function onSwfReceived(e:Event):void
{
swfUrlLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onSwfReceived);
swfUrlLoader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, onSwfIOError);
}
.
That's it ! I don't do anything else besides just loading the external SWF !
The only things that I can think about are:
maybe the 'bad' SWF files have some code-behind in them that causes this behavior to happen ?
the 'bad' banners are supposed to be 906x340. I have noticed that
they have animations flying in from 'outside' those boundries ... (I
found this out by decompiling the SWFs using 'Flash Decomplier'
trial).
Here are the SWF banners that are OK and don't do any problems:
Adom-Adom SWF
Mama Off SWF
Here are the 'bad' banners that make my player go crazy:
Cheese SWF
Emek Cheese SWF
Can anyone help me figure out how to prevent this from screwing up my player, please ?
Thank you for everyone who can help !
it sounds like some of the secondary loads are changing the stageAlign and/or the stageScaleMode. see if changing stage.stageAlign and stage.stageScaleMode to the values you expect after the load is complete fixes the problem

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.

Adding an intro to a swf without access to the fla OR: differences between top-level and loaded swfs

I've got to (quickly!) add an intro to an existing flash masthead on a site that I've inherited. I don't have access to the source .fla's, so I approached the problem by putting the intro in a wrapper swf and loading the current masthead and adding it to the display list on Event.INIT. So far, so good. (Incidentally, the swfs are built for flash player 9 and use AS3.)
The problem I'm having is that although the intro plays fine and loads / displays the beginning of the masthead swf, which is a loading animation, the masthead itself never actually plays. Essentially, my question is: what would cause an actionscript 3-based swf to behave differently when it's the child of another swf as opposed to at the top level of the embedded swf?
Potentially important details: Embedding is being handled with swfobject, and no flashvars are being passed in. There are two params, which are base: "/flash/" and wmode: "opaque". All the swfs and flash data live in /flash/. The flash elements (minus the intro I built) were constructed using the Inky flash framework, with which I'm not familiar.
UPDATE: I've reconsidered my approach to the problem and gotten it working by using ExternalInterface; I'm having the intro swf call a js function when it finishes playing, which swaps out the intro swf and replaces it with the current masthead (the approach is outlined here). I'd still like to know why I was witnessing the behavior I was seeing earlier, though, so any ideas and suggestions would be welcome.
There could be a couple of potential problems with your flash files.
If your swf was compiled in AS2, it could be referencing _root which would be messed up when it is loaded into another swf. In AS2, you can get around it by using _lockroot. In AS3, this is not longer a problem because _lockroot is inheritted.
If your movie was a timeline based movie, you can try to invoke the play() function.
If your intro loads external assets, you will want to make sure your paths are set correctly for all your external assets. Try to put the swf file of your container and the intro in to the same directory. Or troubleshoot by using the Safari Activity window to see if you have any "404 not found".
Another thing is inconsistent flash version. You could run into problem if you load a Flash version 9 with a Flash version 10.
Hope these pointers help.

AS3 - how to start all over again a flash movie

This may be very simple, but I have no idea how to do this.
I created a photo gallery in AS3, everything is on one keyframe. In this photo gallery I have a link to home. My goal is, when someone clicks the "home" link I want everything to start over. Any ideas on how to do this in AS3?
Appreaciate it.
L.
call flash player container
usually the HTML page and use JavaScript to reload the flash player
flash.external.ExternalInterface.call(jsFuncRestart);
jsFuncRestart is a JavaScript function in the HTML file
and now in the js function just create a new object and replace the current flash object
with the new one
You probably animate everything with as3, right? Then just make a reset function that puts all the images back to their original place and start the animation all over.