Flash preloader - actionscript-3

So I've designed a circular preloader that get filled according the percentage of loaded frames.
Everything works great with a frame or two of content aside preloader. When I add the all site with a billion of frames and movie clips, the preloader won't work properly and I'm getting really bored with this because I spent like 4 days trying to understand what is wrong.
Unfortunately, I couldn't find the problem I hope that the pro's can give me an explanation of what is going wrong. Thank you all.
Code from preloader:
import flash.display.*;
import flash.events.ProgressEvent;
import flash.events.Event;
stop();
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, loading);
this.loaderInfo.addEventListener(Event.COMPLETE, loaded);
function loading(e:ProgressEvent):void{
var porcent:Number = Math.floor((e.bytesLoaded / e.bytesTotal) * 100);
porcent_txt.text = String(porcent) + "%";
loader.gotoAndPlay(porcent);
}
function loaded(e:Event):void{
this.loaderInfo.removeEventListener(ProgressEvent.PROGRESS, loading);
this.loaderInfo.removeEventListener(Event.COMPLETE, loaded);
gotoAndStop("enter");
}

You need to check if your library items are not exported to the first frame.
A normal flash file should have nothing except the preloader on the first frame. Don`t use any other classes except the one you need for the preloader in the first frame.

So first of all, thank you very much for your help it was very helpfull
The code was ok
the preloader movieclip was ok also
The problem was on a layer with some text in fact I don't know why this problem happend my guess is that it must be related with deeper problems in my project... don't know
Thank you again.

Related

How To Create a Preloader to a Flash Game

I'm just beginning to get into flash game programming. I know enough to make a functioning project, but not how to make it efficient or do specific tasks, in this case how to add a preloader. I've found several tutorials online, but none that go along with how I've seen is the best method to program. From what I've seen, it is best to program all of my code into one .as file and link this file to the main document. This makes it easy for me to make all of my variables global in scope, which lets me addChild/removeChild in various different functions. The only problem is that I can't find a tutorial on creating a preloader with this method in mind. All tutorials that I've found generally have two frames in the timeline, one with the preloader and one with the content, but I've been told this is not a good way to program. If anyone could help I'd appreciate it a lot. I can paste the source code of one of my learning projects if it would help to provide an answer to my question.
I wouldn't go with the 2 Frame approach. Instead just make your game with your Document Class, like you said you would like to do.
Then when your done, load your compiled game swf into a loader swf.
Here is a simple example on how your loaderSwf should look like:
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;
function startLoad()
{
var mLoader:Loader = new Loader();//Or use ProLoader
var mRequest:URLRequest = new URLRequest(“Game.swf”);
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
}
function onCompleteHandler(loadEvent:Event)
{
addChild(loadEvent.currentTarget.content);
}
function onProgressHandler(mProgress:ProgressEvent)
{
var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
trace(percent);
}
startLoad();
(needs to be wraped in a package and Class if you are using it as Document Class)

ActionScript3 Extrenal Preloader Won't Play Movie Clip

I'm sure this a simple problem and I'm overlooking something obvious.
I have an external pre-loading SWF that contains nothing but a movie clip (loader_graphic) on one layer, in the first (and only) frame; and a loading script on another layer, in the first frame. The movie clip is just a simple loop animation with no progress indicators. If I don't include the script, it works great.
The script loads the external SWF, and by itself, it works just as it should.
When I combine the two, I get the first frame of the movie clip, and then it freezes until the external SWF is fully loaded. Once it's loaded, it plays one time and stops. I'm somewhat new to AS3, and I know that preloading is one of the conventions that has changed, so I probably don't have it coded properly:
loader_graphic.play();
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.ProgressEvent;
var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop);
l.contentLoaderInfo.addEventListener(Event.COMPLETE, done);
l.load(new URLRequest("external.swf"));
function loop(e:ProgressEvent):void
{
var perc:Number = e.bytesLoaded / e.bytesTotal;
}
function done(e:Event):void
{
loader_graphic.stop();
addChild(l);
}
Any help is appreciated.
It turns out that the preloader was playing all along. It was just stalled because the main SWF was overloading the Flash player.
The main SWF it was loading included an F4V video being streamed from a standard web server, and it was too much for the player to handle all at once. I embedded the video, instead, and it all worked perfectly.

As3 Preloader (Blank until 100%)

I have an FLA file with two frames. On the first frame I have nothing but a textfield and some code to do the preloading. After it is done preloading it does gotoAndStop(2)
On frame 1 I have:
stop();
stage.scaleMode = StageScaleMode.SHOW_ALL;
//Import the required assets
import flash.display.*;
//Stop the playhead while loading occurs
this.stop();
//Create a listener to call the loading function as the movie loads;
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, PL_LOADING);
this.loaderInfo.addEventListener(Event.COMPLETE, PL_FINISH);
function PL_LOADING(event:ProgressEvent):void
{
var pcent:Number = event.bytesLoaded / event.bytesTotal * 100;
//Display the % loaded in textfield
txt.text = int(pcent) + "%";
//If the movie is fully loaded, kick to the next frame on the main timeline
}
function PL_FINISH(event:Event):void
{
removeChild(txt);
gotoAndStop(2);
}
On frame 2 I have nothing except:
var game:Game = new Game();
addChild(game);
In my publisher settings I have export to frame 2.
My problem is that the preloader won't display until 100%. Does anyone know why?
P.S. For testing I put a large image file on the stage in frame 2 and the result is the same.
This normally happens if you haven't deselected "Export in frame 1" in each of the library symbols that you are exporting for ActionScript.
You'll need to make sure that you create reference to these objects (so that ActionScript can access them) by placing them onto the stage in frame 2 (out of sight).
What's happening is that all of the symbols are being loaded before the preloader itself has loaded.
If this isn't the issue, then please provide some code so I can better assess your issue.
Have you tried putting something static on frame one? Just because there is a preloader, that doesn't mean that your swf will be displaying at all...
I know that I had one swf once which simply took a minute to actually get the Flex preloader to even show up because of network latency. It could be that your swf isn't displaying until 90% of it has already loaded.
I´m dealing with similar problems, and there is something i found out: my antivirus contains a kind of "browser protection" feature, which sort of checks all files in advance before it allows the browser to actually display them. If this antivirus feature has not been installed on the system, the preloader works beautifully. I´ve checked some other web-sites with flash content, and they also behave "wrong" under these circumstances. Now, some people seem to have found a way to stop the antivirus from messing around, but i don´t know how they do it... not yet...

Actionscctript 3.0 preloader loads once then when the page is refreshed it doesnt load

I have a .fla that has a preloader on frame one and the rest of the file on frames 2 thru 55. The preloader code is the one that comes in Flash cs5's sample files. there is a movie clip with the instance name lbar and text with the name lpc. here is the code
stop();
import flash.display.*;
this.stop
this.loaderInfo.addEventListener (ProgressEvent.PROGRESS, PL_LOADING);
function PL_LOADING(event:ProgressEvent):void {
var pcent:Number=event.bytesLoaded/event.bytesTotal*100;
lbar.scaleX=pcent/100;
lpc.text=int(pcent)+"%";
lpc.z = pcent/100
if(pcent==100){
this.gotoAndPlay(2);
}
}
It works fine the first time people are on my site but when the page is refreshed or is gone back to sometimes the loader bar is just stuck and doesnt load.
Any help is greatly appreciated!
Thanks
The problem was in firefox. It now works because of some javascript coding

FLVPlayback, go fullscreen smooth?

Im looking into using and customizing FLVPlayback in a project. How to go about this is clear, but I noticed 1 anoying thing. When going fullscreen, first Flash player goes fullscreen and then briefly shows the FLVPlayback component in its original size, before jumping to show the video itself fullscreen.
I noticed on Youtube this doesnt happen. How can I escape this 'flicker' and have the video go fullscreen as the videos do on youtube?
Thanks a lot for any tips!
Marcel
in general FLVPlayback along with most of the components built into flash are junk. You are much better off building your own flv player using the NetConnection and NetStream class. Build it once well and generic enough to edit the control visuals and you have yourself a bullet proof flv player for all your projects.
http://actionscriptexamples.com/2008/02/26/loading-flv-files-in-actionscript-30-using-the-netconnection-and-netstream-classes/
Just to say I've used FLVPlayback on jobs many times, and sure it's buggy, but I've never seen this problem. You can definitely fix it. How are you going fullscreen? I've recently being doing something like this...
import flash.display.*;
import flash.events.*;
import fl.video.*;
import flash.geom.Rectangle;
.
.
.
myFLVPlayback.fullScreenTakeOver = false;
mc.stage.fullScreenSourceRect = new Rectangle(0,0,480,360);
myFullScreenButton.addEventListener(MouseEvent.CLICK, onFullScreenButtonClicked);
private function onFullScreenButtonClicked(e:MouseEvent):void {
mc.stage.displayState = StageDisplayState.FULLSCREEN;
}
(though i appreciate you might be using the fullscreen button in an FLVPlayback skin, so this might not be perfect)
NOTE: I just hammered that code in so it might not be perfect/complete. Hopefully you'll find it useful.
++ i'd make sure you set the size and scale of your flvplayback too, e.g. myflvplayback.setSize(w,h)
++ how about myflvplayback.scaleMode = VideoScaleMode.NO_SCALE;