View unanswered posts | View active topics



Reply to topic  [ 54 posts ]  Go to page 1, 2, 3, 4  Next
[Adding a preloader] Loading screen using free tools only. 
Author Message
Member

Joined: Sun Jul 27, 2008 9:15 am
Posts: 3
Location: Moscow
Reply with quote
I am developing a game in FlashDevelop (because it is free IDE). I embed media using [Embed] compiler directives in several classes (because I don't know other ways). Now I want to create a loading screen. I tried to update progress bar using main.root.loaderInfo.bytesLoaded in Event.ENTER_FRAME event where main is reference to the startup class extending MovieClip. But it seems like game is always fully loaded. And I don't understand how Flash Player can understand which pictures in Embed directives should be loaded first.

I found a lot of tutorials in the internet but they all use non-free IDE's (to create a movie clip with several frames that contains necessary data for example).


Sun Jul 27, 2008 9:34 am
Profile
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 12172
Location: London
Reply with quote
Post 
Next release will include pure-AS3 templates with preloader (that's what you need).

But you can configure this manually:

1) Create a Preloader class like this:
Code:
package
{
   import flash.display.DisplayObject;
   import flash.display.MovieClip;
   import flash.events.Event;
   import flash.utils.getDefinitionByName;
   
   public class Preloader extends MovieClip
   {
      
      public function Preloader()
      {
         addEventListener(Event.ENTER_FRAME, progress);
         // show loader
      }
      
      private function progress(e:Event):void
      {
         // update loader
         if (currentFrame == totalFrames)
         {
            removeEventListener(Event.ENTER_FRAME, progress);
            startup();
         }
      }
      
      private function startup():void
      {
         // hide loader
         stop();
         // instanciate Main class
         var mainClass:Class = getDefinitionByName("com.foo.Main") as Class;
         addChild(new mainClass() as DisplayObject);
      }
      
   }
   
}

2) Make the Preloader your project main class (right-click > Always Compile).

3) Now to compile your original main class:
- open the project properties,
- Compiler Options tab > Addtional Compiler Options
- add: -frame main com.foo.Main

So now you have a multiframe SWF, the Preloader can show a splash screen and a loading bar, and your original main class will be compiled in frame 2 of the SWF.

PS: obviously, replace 'com.foo.Main' by your original main class qualified name.


Sun Jul 27, 2008 12:38 pm
Profile WWW
Member

Joined: Mon Jun 18, 2007 2:57 pm
Posts: 117
Reply with quote
Post 
http://www.gamepoetry.com/wpress/2008/0 ... ever-need/

This article has a downloadable class that does most of the gruntwork of Philippe's method for you.

_________________
flash games developer: http://www.urbansquall.com
personal blog and portfolio: http://www.yayitsandrew.com


Sun Jul 27, 2008 4:56 pm
Profile WWW
Member

Joined: Sun Jul 27, 2008 9:15 am
Posts: 3
Location: Moscow
Reply with quote
Post 
I have several classes that embed images (in fact, startup class does not embed any), must I include them to -frame option too (I don't understand the syntax of this option how names of classes should be separated)? Can number of downloaded bytes be obtained as root.loaderInfo.bytesLoaded or this would give the number of downloaded bytes of Preloader class only?


Sun Jul 27, 2008 5:04 pm
Profile
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 12172
Location: London
Reply with quote
Post 
YAYitsAndrew wrote:
http://www.gamepoetry.com/wpress/2008/05/30/the-last-preloader-youll-ever-need/

This article has a downloadable class that does most of the gruntwork of Philippe's method for you.

The article says it will add about 50kb of Flex framework classes - my solution adds 0kb.

halyavin wrote:
I have several classes that embed images (in fact, startup class does not embed any), must I include them to -frame option too (I don't understand the syntax of this option how names of classes should be separated)? Can number of downloaded bytes be obtained as root.loaderInfo.bytesLoaded or this would give the number of downloaded bytes of Preloader class only?

Just works as usual, nothing changes for you*.

The "-frame <name> <classname>" option tells the compiler to add one extra frame (labelled <name>) to compile <classname>. All the classes and embeds that you reference in <classname> will be compiled too.

* Important note: your main class is now a regular DisplayObject, so wait for Event.ADDED_TO_STAGE to know when the stage property will be set.


Sun Jul 27, 2008 5:36 pm
Profile WWW
Member

Joined: Sun Jul 27, 2008 9:15 am
Posts: 3
Location: Moscow
Reply with quote
Post 
Thanks to both of you. My loading screen seems working now (although I can't see the progress without including dummy 2Mb picture :wink: ).


Sun Jul 27, 2008 6:13 pm
Profile
Member

Joined: Sat Oct 20, 2007 8:40 pm
Posts: 24
Reply with quote
Post 
You mean that the first frame should "Preload" the second frame?


Wed Aug 13, 2008 9:11 pm
Profile
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 12172
Location: London
Reply with quote
Post 
omarfouadd wrote:
You mean that the first frame should "Preload" the second frame?

Yes the preloader will be alone (including other classes used in the preloader) on the first frame - the rest of the SWF will be in the second frame.

You don't need to change anything in the Preloader class, except to display something during loading.


Wed Aug 13, 2008 9:30 pm
Profile WWW
Member

Joined: Sat Oct 20, 2007 8:40 pm
Posts: 24
Reply with quote
Post 
and what does this two lines exacty do?

var mainClass:Class = getDefinitionByName("Main") as Class;
addChild(new mainClass() as DisplayObject);

Why I should addChild the Main Class? Why not just make an instance of it for example?


Wed Aug 13, 2008 9:38 pm
Profile
Member

Joined: Wed Aug 01, 2007 3:37 pm
Posts: 1223
Location: Grizzly Flats, CA
Reply with quote
Post 
Flash will compile all of the supporting classes you need to run your content. Ordinarily this is a good and common thing but when you are creating a preloader you want it to load after your preloader begins.

If I understand everything correctly, including "Main" in the preloader code would include all your classes on the first frame. This example pushes Main off onto frame two and uses a weak reference through getDefinitionByName to instantiate your application once it is fully loaded.


Wed Aug 13, 2008 9:50 pm
Profile WWW
Member

Joined: Sat Oct 20, 2007 8:40 pm
Posts: 24
Reply with quote
Post 
But there is nothing that says to go the next frame... what If I add many frames? How can I switch to one of them? What makes the flashplayer get to the Main Frame?


Wed Aug 13, 2008 9:57 pm
Profile
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 12172
Location: London
Reply with quote
Post 
omarfouadd wrote:
But there is nothing that says to go the next frame... what If I add many frames? How can I switch to one of them? What makes the flashplayer get to the Main Frame?

The Preloader class handles it automatically for you. Study it carefully.

FYI the flash player automatically advances to next frame (if any) until you tell it to stop().


Wed Aug 13, 2008 10:06 pm
Profile WWW
Member

Joined: Sat Oct 20, 2007 8:40 pm
Posts: 24
Reply with quote
Post 
oh yes I see now. It has been more than a year I don't work with frames.
Now I understand.

Thanks Philippe.


Thu Aug 14, 2008 12:33 am
Profile
Member

Joined: Mon Jul 02, 2007 1:44 pm
Posts: 20
Location: Belgium
Reply with quote
Does this also works for flex projects?

... which means that my main class is an mxml file.

_________________
Image


Thu Aug 21, 2008 1:26 pm
Profile WWW
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 12172
Location: London
Reply with quote
Gert wrote:
Does this also works for flex projects?

... which means that my main class is an mxml file.

MXML has it's own preloading system.
I think that a preloader is added by default to MXML applications, and there is probably a way to skin it.


Thu Aug 21, 2008 2:22 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 54 posts ]  Go to page 1, 2, 3, 4  Next

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.