How to build an Object-Oriented ActionScript 3 Preloader in Flash CS4: 2 Methods
The magic of creating a preloader in ActionScript 3 lies in the LoaderInfo class. Every instantiated DisplayObject instance (all objects that appear on the stage, plus the stage itself) have a loaderInfo property that returns a LoaderInfo instance that contains information about the loading progress of that particular display object. Creating a preloader for the whole application is a matter of monitoring these LoaderInfo instances.
Method 1: Monitor Stage LoaderInfo instance
Under this method the loading progress is monitored via the LoaderInfo instance associated with the stage. Since all assets that will appear in the application need to be attached to the stage, the stage’s LoaderInfo instance will reflect the loading of all these assets.
Graphics
- Go to File → New… and select Flash File (ActionScript 3.0).
- Using the Rectangle tool create a rectangle (include a stroke) on the stage that is 100 pixels wide by 10 pixels high.
- Click on the fill of the newly created rectangle and select Modify → Convert to Symbol… Name the new instance ProgBar and set the registration point to left-middle. This will be the progress bar of the preloader.

- With the new ProgBar instance selected on the stage, go to the Properties panel and name the instance progBar.
- Select the whole rectangle (stroke and progress bar instance). Select Modify → Convert to Symbol… Name the new instance Preloader and set the registration point to left-middle. Check the Export for ActionScript button.
- Click OK. If you get a warning that says the “definition for this class could not be found” click OK again.
- With the new Preloader instance selected, go to the Properties panel and name the newly created instance preloader. Your library should look like the following:

- Select frame 2 of the main timeline, go to Insert → Timeline → Blank Keyframe. All content for the application will appear on frame 2 and beyond.
- Go to Insert → New Symbol… Name the new instance Content. If you check Export for ActionScript be sure to uncheck Export in frame 1, otherwise the preloader will not function properly.
- Place all content of the application on the timeline of the newly created Content instance.
- Return to the main timeline. Select frame 2 and drag an instance of the Content symbol from the library and place it on the stage.
- In the Properties panel of the stage name the document class Main. If you get a warning that says the “definition for this class could not be found” click OK.

- Save the file.
Code
- Go to File → New… and select ActionScript File.
- Paste the following code and save the file as Preloader.as in the same directory as the .fla file saved earlier.
package { import flash.display.Sprite; import flash.display.LoaderInfo; import flash.events.Event; public class Preloader extends Sprite { /** * Alias for stage LoaderInfo instance */ private var _targetLoaderInfo:LoaderInfo; /** * The percent loaded */ private var _loadPercent:Number = 0; /** * Constructor * Listen for when the preloader has been added to the stage * so that the progress of the remaining load can be monitored. */ public function Preloader() { this.addEventListener( Event.ADDED_TO_STAGE , _init ); } /** * Initialize variables. * Set initial width of the progress bar to 0 * and listen for enter frame event. */ private function _init(evt:Event):void { _targetLoaderInfo = stage.loaderInfo; progBar.scaleX = 0; this.removeEventListener( Event.ADDED_TO_STAGE , _init ); this.addEventListener(Event.ENTER_FRAME, _onCheckLoaded); } /** * Check the status of the load, once complete dispatch a complete event. */ private function _onCheckLoaded(evt:Event):void { _loadPercent = _targetLoaderInfo.bytesLoaded / _targetLoaderInfo.bytesTotal; progBar.scaleX = _loadPercent; if (progBar.scaleX == 1) { this.removeEventListener(Event.ENTER_FRAME, _onCheckLoaded); this.dispatchEvent( new Event(Event.COMPLETE) ); } } } }
- Go to File → New… and select ActionScript File a second time.
- Paste the following code and save the file as Main.as in the same directory as the .fla file saved earlier.
package { import flash.display.MovieClip; import flash.events.Event; public class Main extends MovieClip { /** * Constructor * Stop timeline and add event listener to preloader. */ public function Main() { this.stop(); preloader.addEventListener( Event.COMPLETE , _initContent ); } /** * Load has finished, remove preloader and preceed to next frame. */ private function _initContent(evt:Event):void { preloader.removeEventListener( Event.COMPLETE , _initContent ); this.removeChild(preloader); nextFrame(); } } }
- To test the preloader go to Control → Test Movie. Go to View → Simulate Download.
- Download method 1 complete source
Method 2: Monitor content SWF LoaderInfo instance
Under this method two SWFs are created, one encapsulating the preloader and the other encapsulating all content. The content SWF is loaded inside of the preloader SWF, which monitors the loading progress.
Graphics
- Follow steps 1 – 7 in the previous method.
- In the Properties panel of the stage name the document class PreloaderWrapper. If you get a warning that says the “definition for this class could not be found” click OK.
- Save the file.
- Go to File → New… and select Flash File (ActionScript 3.0).
- Add the content for your application to the timeline of this file.
- Save the file as content.fla.
- Go to Control → Test Movie to create the content.swf that will be loaded by the preloader SWF.
Code
- Go to File → New… and select ActionScript File.
- Paste the following code and save the file as PreloaderWrapper.as in the same directory as the .fla file saved earlier.
package { import flash.display.Sprite; import flash.display.Loader; import flash.display.LoaderInfo; import flash.display.DisplayObject; import flash.events.Event; import flash.events.ProgressEvent; import flash.net.URLRequest; public class PreloaderWrapper extends Sprite { /** * Alias for content LoaderInfo instance */ private var _targetLoaderInfo:LoaderInfo; /** * The percent loaded */ private var _loadPercent:Number = 0; /** * Constructor * Creates Loader instance, adds event listeners and begins loading content SWF. */ public function PreloaderWrapper() { var loader:Loader = new Loader(); _targetLoaderInfo = loader.contentLoaderInfo; _targetLoaderInfo.addEventListener( ProgressEvent.PROGRESS, _loadingData ); _targetLoaderInfo.addEventListener( Event.COMPLETE , _finishedLoading ); loader.load( new URLRequest("content.swf") ); } /** * Monitor loading progress and update progress bar. */ private function _loadingData( evt:ProgressEvent ):void { _loadPercent = _targetLoaderInfo.bytesLoaded / _targetLoaderInfo.bytesTotal; preloader.progBar.scaleX = _loadPercent; } /** * Remove event listeners and preloader, and attach content SWF to stage. */ private function _finishedLoading( evt:Event ):void { _targetLoaderInfo.removeEventListener( ProgressEvent.PROGRESS, _loadingData ); _targetLoaderInfo.removeEventListener( Event.COMPLETE , _finishedLoading ); this.removeChild(preloader); this.addChild( DisplayObject(LoaderInfo(evt.target).content) ); } } }
- To test the preloader go to Control → Test Movie. Go to View → Simulate Download.
- Download method 2 complete source
UPDATE July 30, 2009: I noticed I forgot the private designation on two of the methods in the PreloaderWrapper class. They have been added.

July 11th, 2009 at 6:20 pm
There is a similar method of doing version number one…i find that if you create an instance in the library that is linked to your application class and export those past the first frame…you get a similar effect, also included in this method is a class that allows you to basically set and forget, it will run an update method on the main timeline presenting the progress as a parameter, its really easy, and takes the guesswork out of this.
http://blog.tylermadison.info/?p=13
July 13th, 2009 at 3:12 am
Hi Tyler,
Thanks for sharing your method. Also, nice tip on setting the export frame in the publish settings. Here’s an optimization you might try… instead of passing in a string for the main class definition, pass in the actual class definition instance. I haven’t benchmarked it, but I suspect getDefinition(.) is quite a slow method. Change the following lines and you can avoid having to look up the class. It also feels cleaner IMHO.
Line 11:
private var _className :Class;
Line 13:
public function ExportTroller(root:MovieClip , mainClassName:Class , frameExportNumber:int = 2, updateFunction:Function = null) {
Line 46:
var main:DisplayObject = new _className;
Also, in your imports… add:
import flash.display.DisplayObject;
July 13th, 2009 at 10:25 am
Just a hunch cause I haven’t tried yet but I am guessing that this will one, cause a compiler error or two, bypass the reason for exporting on frames past the first frame. I’ll give it a try and get back to you, thanks!
July 13th, 2009 at 10:38 am
Yes, my suspicion is confirmed, if you import the main class at all in your first frame script, there’s no point in preloading the class exports, because anything that is referenced in the main class will also be exported on the first frame as well. In the bandwidth profiler the k size from the first frame shoots up from about 2kb (loader and troller class) all the way to about 17kb.
July 13th, 2009 at 5:06 pm
Huh. I’m not seeing this effect, the bandwidth profile for both methods is the same from what I can see. Wonder what is different between your setup and mine. What you are saying makes sense, though I’m wondering… if you import a class definition, the class has not yet been instantiated, so I wouldn’t think it would need to import all referenced assets until it was instantiated on frame 2.
July 13th, 2009 at 7:06 pm
Ok, I think I figured it out…check out this demo if you get a chance, its using the class reference and the problem is clear, even thought the bulk of the library asset(bitmap embedded in the symbol) gets deferred until the 2nd frame its clear when i added the TweenLite tweening package to the Main.as class that the k size in the first frame jumped up to nearly 10k, even though I instantiate it with the class reference, this is what I was eluding to during my method demonstration…please let me know if you get the same result, and try to remove the tweening package and record what k size you get in the first frame.
thanks!
tyler
July 13th, 2009 at 7:07 pm
sorry here is the link to the example…
http://blog.tylermadison.info/wp-content/source/export_test.zip
July 23rd, 2009 at 6:49 am
Sorry for the belated reply. Yes, I do see that jump. That makes sense because you are importing the class structure, however, the class instances will get deferred as you mention. I guess it comes down to a balance of whether strict typing is quicker versus a smaller initial footprint. If your classbase is small, strict typing may be the way to go, but if your application is elaborate, performing a lookup for the class may be preferable. I’ll post if I see a better solution, thanks for your method and discussion
July 29th, 2009 at 9:54 am
I just want to get clarification on method 2. In effect, if you make a preloader this way, you’ll have a preloader swf that you never need to touch again, correct?
In other words, I can just copy the preloading swf and focus entirely on my content swf (or even dynamically reference various content swfs from external HTML, PHP or what have you) forever without having to actually rebuild the preloader, barring any design alterations.
July 29th, 2009 at 6:57 pm
Hi Val,
Yes, that is correct, the only thing the PreloaderWrapper cares about is the name of the swf it is looking for (in this case “content.swf”).
July 29th, 2009 at 7:03 pm
Good question, there is a yes and no answer to that you can decide which is best…
You can if your implementation is generic enough…however, a lot of times you want to preload other assets (FLVs, JPGs, and sounds) in addition to monitoring the progress of the main .swf. This is where it gets complicated, and I would recommend using the method that I had described above, keeping everything to one .swf but exporting your classes in any frame EXCEPT the first frame, so that you can monitor progress of the entire swf being downloaded in addition to preloading any assets that are absolutely necessary before your main class gets instantiated.
August 7th, 2009 at 7:44 am
Hi Tyler,
Have been trying to use the method 1 preloader but not having any joy at all. I have two images (contained within movie clips) in frame two that have some functionality attached to them but they don’t want to appear after the preloaders finished doing its magic. What’s strange is that when you refresh the swf the browser has cached it and the images load straight away without the preloader being shown (or for maybe 500ms). If you could have a look it would be much appreciated, I’ve uploaded several files for testing:
http://www.core.je/test/preloader1.swf (you’re preloader with an image on frame 2)
http://www.core.je/test/preloadertest.zip (my fla with your preloader method 1 applied)
http://www.core.je/test/BugSafariExplorer.swf (published swf frrom my fla)
Any help’s appreciated. Thanks.
Cheers
Rich
August 7th, 2009 at 7:51 am
Sorry I meant ‘Hi Anselm’… I was reading Tyler’s latest post whilst writing mine ha!
Cheers
Rich
August 7th, 2009 at 8:43 am
Hi Rich!
Since your images are quite large this error is appearing because of a rounding error. And it’s actually an error in my code, so thanks for discovering it!
In Preloader.as you will find the line:
if (_percentLoaded >= 100) {
Since your images are large, it reaches 100 percent on the preloader before the last bytes have actually been loaded, so the application thinks the loading is done before it actually is. It then removes the preloader graphic and attempts to go to frame 2, but is unable to do so because it hasn’t quite finished loading that frame.
To correct this change the above line to:
if ( _loaderInfo.bytesLoaded == _loaderInfo.bytesTotal) {
This is a much more accurate way to handle the end of the loading process, because it is looking at the actual bytes loaded as opposed to a percentage extrapolated from the bytes. I’ll update the actual post source code when I get a chance.
Best wishes,
Anselm
August 7th, 2009 at 9:39 am
Anselm, you’re an absolute legend thank you so much. I should have seen that (and the fact I was ‘ceil’ing the percent rather than ‘floor’ing!) myself really, schoolboy error! The final product is up at http://www.bugsafari.je/habitats/garden-long-grass.html. Thanks so much again!
Cheers
Rich
August 20th, 2009 at 12:06 pm
When I’m preloading a swf that is also linked to an .as file, I get this:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at SlidingIcons/init()
at SlidingIcons()
August 22nd, 2009 at 2:25 am
Hi Eran,
It doesn’t have to do with the fact that your .fla is using an external .as file (remember the swf is the compiled version of the AS code, regardless of whether it’s on the timeline or is an external file), but rather it has to do with the contents of your AS code. What does your init function look like in the SlidingIcons class?
Also, you may want to read my post on error #1009, available here: http://blog.anselmbradford.com/2009/02/26/common-flash-errors-1009-cannot-access-a-property-or-method-of-a-null-object-reference/
September 6th, 2009 at 6:47 pm
Really thanks buddy.
September 14th, 2009 at 9:50 pm
Brilliant preloader solutions! I tried about 20 “simple tutorials” and all of them failed. Yours are clean and elegant!
Thank you!
September 15th, 2009 at 2:17 am
Hi Casey,
Glad they helped out
Cheers
September 25th, 2009 at 3:35 pm
TypeError: Error #1010: A term is undefined and has no properties.
at PreloaderWrapper/_loadingData()
October 8th, 2009 at 12:16 pm
Does this work for assets as well or just the SWF? I’m trying to find the best way to preload assets, suhch as FLV files into the preloader. I have had no luck.
October 8th, 2009 at 9:04 pm
Hi Kevin,
Yes and no, replace “content.swf” with “pic.jpg”, for instance, and you can load a JPG image instead. The Loader class can load “SWF files or image (JPG, PNG, or GIF) files.” FLVs use their own loading and display classes, namely NetStream, NetConnection, and Video.
November 2nd, 2009 at 4:05 pm
One issue with your loader. During the preloading. The SWF inside is already playing even the loader will actively showing update progress. When it hits 100%, whatever movie behind the SWF is already half way playing it.
November 2nd, 2009 at 9:21 pm
If I understand correctly you are saying the container SWF (preloader2.swf in the downloads) plays while loading in the other SWF (content.swf in the downloads)? Is that correct? The preloader swf should only be one frame, since the sole purpose of this is to provide a wrapper for the actual content. However, should you have multiple frames on the wrapper you can modify the PreloaderWrapper.as file in the following ways to fix the issue you are experiencing:
1) Import flash.display.MovieClip at the top.
2) Make it extend MovieClip instead of Sprite.
3) In the constructor function add:
this.stop();
4) Inside the
_finishedLoadingmethod addthis.play();.This will stop the playhead from moving until the content has finished loading.
November 4th, 2009 at 4:51 pm
Thanks for the reply,
I am using Method 2, loader.swf is the Preloaderwrap and the movie.swf is the movie swf with flvplayer and animations in it.
I did add those codes in, but ends up showing errors because “this” isn’t targeting to any instances. Not sure where I did wrong.
That is the point, to have it play only when it hits 100%. Right now, it acts like streaming behind the loader bar.
November 5th, 2009 at 5:39 pm
Nice. Good job
November 10th, 2009 at 11:13 am
Hi, I’m learning AS3, moving on from AS2. Been away for a year traveling. I’m wondering why is it that when I preview your preloader 1 solution, and I’m simulating bandwith. (Basically Command + Enter) the second time I get:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Main/_initContent()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at Preloader/_onCheckLoaded()
November 10th, 2009 at 11:29 am
Daaaa,
Hmm… yeah you have a syntax error somewhere, using
thisshould not throw an error.Is your document class set to
PreloaderWrapper?November 10th, 2009 at 11:33 am
Hi Arthur,
You get this from downloading and trying the source unmodified? I don’t see this. Are you using Flash CS4?
I have a post on error #1009 by the way: http://blog.anselmbradford.com/2009/02/26/common-flash-errors-1009-cannot-access-a-property-or-method-of-a-null-object-reference/
November 17th, 2009 at 2:10 pm
I’m getting the null object reference too, but when I test my content SWF alone, I get no error. How can this be? I’ve scanned my code for object variables, and they all are set properly as far as I can tell.
November 17th, 2009 at 4:43 pm
I solved my null object reference error by removing these lines from my main class constructor:
stage.align=StageAlign.TOP_LEFT;
stage.scaleMode=StageScaleMode.NO_SCALE;
It worked fine after that. I guess ‘stage’ was the null reference (?)
November 17th, 2009 at 9:44 pm
Hi Mark,
Ahh yes, this is a classic one. What you want to do is add this line to your constructor:
this.addEventListener( Event.ADDED_TO_STAGE , init );And then create a method in your class:
private function init( evt:Event ) : void
{
stage.align=StageAlign.TOP_LEFT;
stage.scaleMode=StageScaleMode.NO_SCALE;
}
This way the reference to the stage will only occur when the stage property has been set.
February 10th, 2010 at 9:55 pm
Thanks for the write-up Ans. Very useful =)
I have a query, though it’s slightly off-topic, concerning generic OOP design in AS3. After you have incorporated a preloader using the first method, do you keep your main/container swf relatively empty and then load external swf’s for the the actual content, ie, each page?
In AS2 I would always try to keep the size of the main swf as low as possible to speed up initial download and then load further content when required (working example: http://www.ahern.com.au). Though I am trying to work out how best maximise the power of AS3′s OOP to achieve this. In your personal opinion, is it even worth loading it seperately like that?
Wouldn’t mind hearing other pps opinions on this also.
Thanks
Ryan
February 11th, 2010 at 3:36 am
Hi Ryan,
Thanks for the comment. It really depends on how large your combined swf would be. Loading in external swfs at runtime spreads the loading out, giving a better experience to the user, but it may well not be necessary if your total load size is small, and you’ll actually be adding in code and complexity that isn’t necessary in that case.
August 5th, 2010 at 10:55 am
Great post!!! Just what I needed.
October 28th, 2010 at 9:00 am
Thank you! this is a great tutorial. It was just what I needed for my project. I made a few small modifications (not improvements) where rather than dragging the ‘Content’ onto the stage in frame 2 I added it this way instead:
nextFrame();
var c:Class=root.loaderInfo.applicationDomain.getDefinition(‘Content’) as Class;
var m:*=new c(this);
addChild(m);
As Tyler mentioned using getDefinition meant that It was not loaded early.
Thanks again. Respect for: taking the time to post this, the good work and your high google ranking.
Shaedo
October 28th, 2010 at 3:34 pm
Hi Shaedo,
Thanks for the kind words!
November 9th, 2010 at 12:00 pm
Hi Ans,
Great job on this and i have a quick question…
I’m using the 1st method you outlined on this page and i have my main content sitting in a clip called \content\ on frame 2. Now say my content clip has a button within it called \btn1\. At what point do i assign listeners for this button in the Main.as class? I’ve tried to call a function called \init\ within the Main.as class (i call it right after the nextFrame() statement in the _initContent method), but i’m getting the usual \TypeError: Error #1009: Cannot access a property or method of a null object reference\ when i try to reference the \btn1\ within my \content\ clip. Thanks in advance for any help you can provide. -David
November 10th, 2010 at 2:07 pm
Hi David,
Likely your code is still running on frame 1, so it is not aware of btn1. Here are a few thoughts:
1) Check into the
addFrameScriptmethod, which allows you to execute a function on a particular frame: http://blog.newmovieclip.com/2007/04/30/add-a-frame-script-addframescript-dynamically-in-flash-cs3/2) You could listen for an
Event.ENTER_FRAMEevent and have an if statement at the top that said:private function _handleEnterFrame( evt:Event ) : voidif (this.currentFrame == 2)
{
trace(content.btn1); //get access to btn1 inside the content movieclip
}
}
3) Create a class file for the content. Create a duplicate of Main.as and name it Content.as… remove all functions except for
public function Main(). Rename this functionpublic function Content. Renameclass Maintoclass Content. Insidepublic function Contentadd the event listeners for your button, e.g.:trace(this.btn1);
if (this.btn1)
{
this.btn1.addEventListener( MouseEvent.MOUSE_DOWN , btn1Pressed );
}
Cheers!
November 10th, 2010 at 4:39 pm
Hi Ans,
Yep – I had created a separate class called Content to handle the functionality of the content movie clip but when i referenced the button in the content clip, my path was messed up. I was using cont.mybutton.addEventListener (where “cont” was the instance name of the content clip). I changed “cont” to “this” and it works fine now. Forgot that i didn’t need the “cont” in the path as “this” refers to “cont”.
Thanks so much for your help Ans – I’m off and running now.
PS: Thanks for your other suggestions as well!
Best,
David
March 11th, 2011 at 3:49 pm
hi and thx for the tuto
im a real bigginer in as3 and im trying to preload a vid (flv) and this is the only way that i succeced but i have only one problem
when i lunch its start corectly but the video start after 5 or 6 s ,the backgroun is black so cant see the vid but the is the sound in in the end of the vid we can see the end of the vid
(the preloader lunch the vid befor it load it all)
[1) Import flash.display.MovieClip at the top.
2) Make it extend MovieClip instead of Sprite.
3) In the constructor function add:
this.stop();
4) Inside the _finishedLoading method add this.play();.]
i think this is the solution like and said it but (sorry) im a bigginer and dont know where to chage all that
pls help me im going be mad (only that for a preloader ) …
thx
March 11th, 2011 at 3:57 pm
pls can someone do it for me and send me the file ??? or upload it some where ??
thx
March 15th, 2011 at 9:21 am
when i put this on the server my preloader (for both methods) bar is stretching to the left all the way…?
and stays that way until things are finally loading…essentiallly not working…
when i add a txt field to show me the percent loaded..it goes to infinity or straight to 100%..then waits until it is finally loaded ( essentially not working..)
Any ideas of what i am doing wrong…? It works this way for me without any modifications
I have tried it with putting the this.stop(): and this play(); too
Thank you
March 15th, 2011 at 4:07 pm
Hi,
Try testing it in simulate download mode with the bandwidth profiler and see what is loading. It’s under View -> Simulate Download and View -> Bandwidth Profiler after testing the SWF. Perhaps you have something large on the stage before the preloader (which needs to load before the preloader is shown) or perhaps it’s loading too quickly, thus going from 0% to 100% nearly instantly (in which case you wouldn’t really need the preloader).
March 15th, 2011 at 4:29 pm
Hi
thanks for your response–
Ihave been at this ALLL DAY–thought i was crazy but feel it has something to dowith the server
Here is an example on a server and it works fine — [URL removed]/loadtest/preloaderTyping1.swf
but on this other server…doesnt work…
looks like this
[URL removed]/renee_test/typing/preloaderTyping1.swf
server issue? what kind of server issue ( your preloaders are a great find–just need to work them out for this server)
Any ideas?
thanks in advance
March 15th, 2011 at 6:13 pm
Renee,
Off the top of my head I’m not sure what the issue would be, however, as it works on some servers and not others, that would point to a specific configuration issue with the server it has an issue with (as you speculated). You could temporarily place a textfield on your stage and use the example on: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/URLLoader.html#includeExamplesSummary to test the loading process (changing the trace() statements with myTextField.text = ). This will let you know if you’re getting any server errors during the loading, though I would think those would mean the SWF would stop loading completely, which doesn’t appear to be the case.
March 15th, 2011 at 6:20 pm
Hi Ans-
ok–yes they do acually load eventually — I am still diggin into this..
It is an apache server and I have read it could perhaps have something to do with the mod_Deflate settings and swf not playing well together, but do not yet know what or where to change this..
This is where I am now….
March 15th, 2011 at 6:32 pm
Ans -
I received no Erros when running the example on my server..
renorigs
March 15th, 2011 at 7:26 pm
i found if i add |swf| to the mod_deflate (.htaccess file) your preloader will fucntion in FF BUT not IE —
So I am close but still do not have this figured out…
March 15th, 2011 at 9:16 pm
well, I have a solution to my problem…it doesn’t matter what preloader I use ..I will have the problem on this Apache server..
But I have fixed my issue
It has to do with server settings compression and flashplayer can’t tell the size of the file..
rather than me explain just use these links to help you understand to rewrite a modDeflate rule in htaccess file
http://flashscript.ca/preloader.php
and
http://www.philchen.com/2009/08/04/apache-mod_deflate-and-flash-swf-files-dont-like-each-other
for me IE works only if you put this file in the same folder –
thank you Ans and goodNight!
March 15th, 2011 at 9:43 pm
Thanks for the solution!
May 16th, 2011 at 8:57 am
Hi, If i create new project this code work fine. but If I insert this code to my own document class, its not work. can any one help??? please thanks..
my document class…
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
package com.ahmad.bg
{
//import all classes
import caurina.transitions.Tweener;
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageDisplayState;
import flash.display.StageScaleMode;
import flash.events.Event;
//import flash.events.FullScreenEvent;
import flash.events.MouseEvent;
import flash.net.URLRequest;
/**
* …
* @author …Ahmad Yousaf – http://www.ahmadyousaf.com | [email removed]
*/
public class MainClass extends MovieClip
{
//create variables
private var loader:Loader;
private static const IMAGE_PATH:String = “bgs/bg.jpg”;
public function MainClass() {
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(Event.RESIZE, stageResize);
//load external image
loader = new Loader();
loader.load(new URLRequest(IMAGE_PATH));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, showImage);
pic.addChild(loader);
/*stage.addEventListener(FullScreenEvent.FULL_SCREEN, onFullscreen);
bottomNav.fullscreen_btn(root).addEventListener(MouseEvent.CLICK, goFullscreen);
bottomNav.fullscreen_btn(root).buttonMode = true;
}
private function onFullscreen(e:FullScreenEvent):void
{
bottomNav.fullscreen_btn(root).gotoAndStop(e.fullScreen?2:1);
//stage.bottomNav.fullscreen_btn.gotoAndStop(e.fullScreen?2:1);
}*/
}
private function showImage(e:Event):void
{
try {
e.target.content.alpha = 1;
Tweener.addTween(e.target.content, { alpha:1, time:1, transition:”easeOutSine” } );
e.target.content.smoothing = true;
} catch (e:Error) { };
stageResize();
}
/*private function goFullscreen(e:MouseEvent):void
{
if( stage.displayState == StageDisplayState.NORMAL ){
stage.displayState = StageDisplayState.FULL_SCREEN;
} else {
stage.displayState = StageDisplayState.NORMAL;
}
}*/
private function stageResize(e:Event=null):void
{
pic.x = 0;
pic.y = 0;
pic.scaleX = pic.scaleY = 1;
if ((stage.stageHeight / stage.stageWidth) < pic.height / pic.width) {
pic.width = stage.stageWidth;
pic.scaleY = pic.scaleX;
} else {
pic.height = stage.stageHeight;
pic.scaleX = pic.scaleY;
};
pic.x = stage.stageWidth / 2 – pic.width / 2;
pic.y = stage.stageHeight / 2 – pic.height / 2;
//fullscreen_btn.x = Math.floor(stage.stageWidth – fullscreen_btn.width – 10);
//fullscreen_btn.y = 10;
bottomNav.x = Math.floor(stage.stageWidth / 2 – bottomNav.width / 2);
bottomNav.y = Math.floor(stage.stageHeight – bottomNav.height – 0);
}
}
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
May 16th, 2011 at 8:59 am
how can I use this code to my document class??? Thanks..
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
package
{
import flash.display.MovieClip;
import flash.events.Event;
public class Main extends MovieClip
{
/**
* Constructor
* Stop timeline and add event listener to preloader.
*/
public function Main()
{
this.stop();
preloader.addEventListener( Event.COMPLETE , _initContent );
}
/**
* Load has finished, remove preloader and preceed to next frame.
*/
private function _initContent(evt:Event):void
{
preloader.removeEventListener( Event.COMPLETE , _initContent );
this.removeChild(preloader);
nextFrame();
}
}
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
May 16th, 2011 at 6:03 pm
Hi Ahmad,
You set it as the document class… see http://active.tutsplus.com/tutorials/actionscript/quick-tip-how-to-use-a-document-class-in-flash/
EDIT: sorry didn’t see your prior message. I’m not sure what the issue is, try adding your code to the new project that works, instead of the other way around. Also, do this piece by piece, checking along the way.
May 17th, 2011 at 1:25 pm
Thanks Ans for Reply.
Let me clear you my Issue. I know how to attach a document class with fla file… I just want to ADD Object-Oriented Preloader to my already made document class. Means I want to use this Preloader Tutorial to my AS file. I’ve already posted above my document class and I want to add this tutorial’s script to my class.. When I try to add this tutorial script to my document class, it getting error not working.. because at 1st frame of my Fla I’m using a movie clip to load an image… when i shift my content to the 2nd frame the Class not work..
I hope you understand… Now again I’m posting my document class….
////////////////////////////This is my document Class which I’m Using Already/////////////////////////////////
package com.ahmad.bg
{
//import all classes
import caurina.transitions.Tweener;
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageDisplayState;
import flash.display.StageScaleMode;
import flash.events.Event;
//import flash.events.FullScreenEvent;
import flash.events.MouseEvent;
import flash.net.URLRequest;
/**
* …
* @author …Ahmad Yousaf
*/
public class MainClass extends MovieClip
{
//create variables
private var loader:Loader;
private static const IMAGE_PATH:String = “bgs/bg.jpg”;
public function MainClass() {
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(Event.RESIZE, stageResize);
//load external image
loader = new Loader();
loader.load(new URLRequest(IMAGE_PATH));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, showImage);
pic.addChild(loader);
/*stage.addEventListener(FullScreenEvent.FULL_SCREEN, onFullscreen);
bottomNav.fullscreen_btn(root).addEventListener(MouseEvent.CLICK, goFullscreen);
bottomNav.fullscreen_btn(root).buttonMode = true;
}
private function onFullscreen(e:FullScreenEvent):void
{
bottomNav.fullscreen_btn(root).gotoAndStop(e.fullScreen?2:1);
//stage.bottomNav.fullscreen_btn.gotoAndStop(e.fullScreen?2:1);
}*/
}
private function showImage(e:Event):void
{
try {
e.target.content.alpha = 1;
Tweener.addTween(e.target.content, { alpha:1, time:1, transition:”easeOutSine” } );
e.target.content.smoothing = true;
} catch (e:Error) { };
stageResize();
}
/*private function goFullscreen(e:MouseEvent):void
{
if( stage.displayState == StageDisplayState.NORMAL ){
stage.displayState = StageDisplayState.FULL_SCREEN;
} else {
stage.displayState = StageDisplayState.NORMAL;
}
}*/
private function stageResize(e:Event=null):void
{
pic.x = 0;
pic.y = 0;
pic.scaleX = pic.scaleY = 1;
if ((stage.stageHeight / stage.stageWidth) < pic.height / pic.width) {
pic.width = stage.stageWidth;
pic.scaleY = pic.scaleX;
} else {
pic.height = stage.stageHeight;
pic.scaleX = pic.scaleY;
};
pic.x = stage.stageWidth / 2 – pic.width / 2;
pic.y = stage.stageHeight / 2 – pic.height / 2;
//fullscreen_btn.x = Math.floor(stage.stageWidth – fullscreen_btn.width – 10);
//fullscreen_btn.y = 10;
bottomNav.x = Math.floor(stage.stageWidth / 2 – bottomNav.width / 2);
bottomNav.y = Math.floor(stage.stageHeight – bottomNav.height – 0);
}
}
}
////////////////////////////My Document Class Ended Here/////////////////////////////////
———————–
////////////////////////////This Tutorial Script I want to Add my above mentioned Class/////////////////////////////////
package
{
import flash.display.MovieClip;
import flash.events.Event;
/**
* @author Anselm Bradford – anselmbradford.com
*/
public class Main extends MovieClip
{
/**
* Constructor
* Stop timeline and add event listener to preloader.
*/
public function Main()
{
this.stop();
preloader.addEventListener( Event.COMPLETE , _initContent );
}
/**
* Load has finished, remove preloader and preceed to next frame.
*/
private function _initContent(evt:Event):void
{
preloader.removeEventListener( Event.COMPLETE , _initContent );
this.removeChild(preloader);
nextFrame();
}
}
}
/////////////////////////Ended Tutorial Script/////////////////////////////////
June 23rd, 2011 at 12:02 am
Thanks maaaate! I didn’t think to create a LoaderInfo object, solved all my problems!