A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Dealing with preloaders in OOP AS3

  1. #1
    Member
    Join Date
    Dec 2007
    Posts
    85

    Question Dealing with preloaders in OOP AS3

    So apparantly I'm stupid. To date, anything I've had to do when programming in Actionscript 3 has boiled down to one of two situations that has, for the most part, made it all easier for me:

    - I am doing the coding in frames, allowing me to use a preloader built in the same manner (Which is how I'm used to preloaders). Typically it was a small amount of programming.

    - I am building something where I don't need to worry about download times and such, as the files will only be viewed offline directly off someone's hard drive. This meant I didn't need a preloader. This is the situation whenever I had to work with document classes.

    However, I am working on a project that is a little... too big to be done in the first method, but I have no experience with preloaders when using a document class. I've done some research on how to do it, but I found that the methods used have one of two problems:

    - A built-in preloader won't deal with linkage as part of the loading process, as it were, and thus if I have any movieclips with AS3 linkage (Which I will have a lot, and they will comprise at least half of the file size which I'm already predicting to be 10 to 15 MB), it means the preloader is going to be retarded and not show this properly.

    or

    - Using an external file to store the content and load it in, which is not an option since I want it contained all in a single file.


    So I'm now trying to play with a way to use preloaders I know and combine them with a document class. Is it as simple as I'm looking at it? Can I just built a preloader movieclip, throw it into the first frame, and have it that when the preloader ends it will make the document class run a function that then chains everything else (And thus the constructor for the document class doesn't really do anything, since it will not be running anything)? Or is there another way I can proceed that will make more sense and make me look less like an idiot?

  2. #2
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    It really depends on what it is you are "preloading". You don't have to use a document class , you can have you preloader on your first frame like you always do , when its finished , advance the playhead to frame 2 or whatever , and just say var main : Main = new Main(); So basically main , would be a symbol in your library , exported for actionscript , and linked to some package somwhere , com.bleh.Main. This will kinda preload , but does not take into consideration anything dynamic you add after the contructor is called. When i build in as3 and or flex , i do differed loading. Or a lot of time ill use an initial loader , or asset loader to load attached content , which i do not export on the first frame, rather leave on stage , on like frame 5 , in empty movieclip. This gives me an acurate intial load , then as i step through the initialization process , i update a sort of process loader , to give the end user a more acurate idea of whats being loaded and how long its going to take. Like adding nav items , parsing xml , not just loading it. So by the time the loader is done, my application is truly init , and ready to be shown.

    If your Main class extends movieclip or sprite you can add it to stage ,

    addChild( main );

  3. #3
    Member
    Join Date
    Dec 2007
    Posts
    85
    What I am preloaded is something around 150 movieclips, each with their own animations, masking, etc etc and each having linkage to be used in the code, a number of wav format vocal sound clips, and a few song tracks. It's all part of a demo for a game I am building (To which the full game is bound to end up having so much more than this demo will.)

    What I think I need to set-up, which I'm not used to doing, is a partial preload of sorts: preload all the content I need up to a certain point. This would be up to a settings page, after which the player would get to play the demo itself (Up to this point, there are two logo animations with their own sound clips, a sort of intro animation, the settings page itself, and a number of voice clips designed to accompany the intro stuff. It will take 30 seconds to a minute for a player to go from the preloader to being able to fully do anything besides a "press start to play" deal, during which time I know I could continue to load stuff (In particular, movieclips and sound files I know will be used. The song tracks I mentioned earlier, I only need to load one at a time, so as long as I can prioritize one song track to load before the others then while the player is trying the demo the rest can load).

    Of course, saying all that makes me realize how bad I am when it comes to dealing with loading content. Ugh... I'll need to read up more on that.

    Anyway...

    So don't use a class document, but still have a class file that frame 2 would call. To tie it in would be a symbol in the library that is exported for AS, where the class name would be "Main" and the Base Class would be the class file in the package? I can then treat the class file almost like a class document (Or at least in terms of how I know), where I would work everything through what I added in the second frame of the timeline...

    So then maybe something like this:

    Code:
    var main:Main = new Main();
    addChild(main);
    This would then make an object based on Main, which gives me all that coding. This makes me have to ask one thing, though: Can I explicitly use the movieclips I export for actionscript that carry animations in the code in the class file? Like, by name.

    So say I have a movieclip that is exported for AS, and it's called "ET." In that class file, can I then go something like var somename:MovieClip = new ET(); and then continue to reference somename in that code and have it actually work? I would assume yes, but given I'm used to working with making my first class as a document class (and do any referencing of exported movieclips in that class) I'd rather not be caught being stupid.

    Oh, and if I seem like I ramble a bit, sorry. It tends to be how I think best.

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Unless you have a lot of bitmaps directly in your movie you don't need a preloader.
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    not true at all. 150 movieclips all with their own aniamtions and timelines sounds like you would want a preloader. Especially if you are not differing that load in anyway and doing it all up front. One sizable bitmap with moderately high compression settings will cause latency on slightly slower connections. If you have a lib with loads of heavy vector assets youll need preloader. If you have a 25,000 line xml file to load and parse , and or do anything data driven , youll need a preloader. If you have lots and lots of dynamic , run time , things you need to set up like , navs , sub navs, anything particle related , you will want a process loader , or tack those intialization processes into your preloader.

    To answer your questions about ET , if you export a symbol from the library for actionscript , give it a linkage name of ET , but assign it no class path , and just have its base class be movieclip or spirte , you can still reference it your Main.as class. It would just be

    private var someClip : Movieclip();
    someClip = new ET();
    addChild( ET );

    now if you want that clip to have mouse events associated with it ,or any sort of unique behavior i would suggest not doing it the former , but writing a seperate class for it.

    package com {
    public class ET extends MovieClip {
    public function ET() {
    super();
    };
    };
    };

    then you can just add that package to the lib symbol ,

    com.ET

  6. #6
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Not if you reuse movieclips and have different instances of them. Regarding animations they are cpu intensive. Even if you preload you will have problems playing them. I recommend always to split up one large movie into several smaller movies and load them at the given time.
    - The right of the People to create Flash movies shall not be infringed. -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center