A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: Going Crazy, loader, simple file example included

  1. #1
    Senior Member
    Join Date
    Apr 2000
    Location
    Minneapolis
    Posts
    2,127

    Going Crazy, loader, simple file example included

    Hi,
    I am using the bulkloader class which I was directed to on this board.
    It is really good, but is proving beyond my AS3 knowledge.
    It can be found here
    http://code.google.com/p/bulk-loader/

    I have attached a zip file with everything needed to look at my problem in its simplest form.
    basic_shell.fla includes the class basic_bulk.as
    this loads partA.swf and partB.swf in sequence.
    It displays percent loaded of the total for both files in a textbox.
    This much works fine

    There is a button in partA.swf that should load partC.swf, does not work.
    The textbox in basic shell should display the percent loaded for partC.swf, does not work

    NOTE All the loading is handled in basic_bulk.as
    I have not been able to get this working in the basic_bulk.as
    My last attempt is commented out in the .as file.
    All the files are in fla form, just export swf's.
    all class files are included in the correct folder setup.

    I am in over my head!
    I have stripped this down to absolutely basic, so hopefully someone will take pity and take a look.

    thanks
    mark
    Last edited by mgason; 07-10-2009 at 05:20 PM.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Wish I could help you more, but a) even though I recommended bulk-loader, I've never used it, and b) I can't open fla files.

    I did take a look at basic_bulk.as. I did not see the part that loads partC. Can you post the relevant code in this thread?

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    If the commented out stuff was the C loading code, then I see a couple of problems.
    First, you're calling pause before instantiating the loader. You'll get a nullpointer there. Second, the method is called basic_bulk(), which conflicts with the constructor.

    Other than that, any problems look minor.

  4. #4
    Senior Member
    Join Date
    Apr 2000
    Location
    Minneapolis
    Posts
    2,127
    Hi,
    yes the commented out stuff was my last attempt. It works fine without that.
    I really like this loader. I have it doing quite a bit of stuff with the first load that would be impossible for me to achieve on my own. Not in the basic_bulk.as I posted. That is stripped down to minimal functionality.

    Nothing I read in the documents or forums gets into any detail on how to have a second loader instance (or 3rd or 4th). They assume a pretty good knowledge of AS3 and just say make another instance.

    So let me display my ignorance, this went over my head "Second, the method is called basic_bulk(), which conflicts with the constructor"

    I see the pause issue, oops. Looks like I may not need it anyway, docs say "BulkLoader will only begin loading once you call the start method:"

    The other issue is how do I make a button in partB.swf run the load for C.

    I have read the whole google forum, here is the closest post I can find to what I want. As you can see the answer is less than detailed
    http://groups.google.com/group/bulkl...b2d2d77ea6f631
    I added the commented code back in.
    removed the pause, and put in a start. Just trying to get it to run before dealing with the button problem. It throws this 1 error.

    Description
    Multiple constructor definitions found. Constructor may not be defined in <Script/> code.
    Source- Line 84
    public function basic_bulk() {

    I figure if I can get 2 basic loads working and a button I can expand it to several complex ones. The loader itself makes sense.

    mark

  5. #5
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Your class is called basic_bulk. You can only have one method by that name in that class, and that method is the constructor. If you want to have a second method that loads things differently, name it something else.

    The multiple constructor error is what I was trying to warn you about.

  6. #6
    Senior Member
    Join Date
    Apr 2000
    Location
    Minneapolis
    Posts
    2,127
    Hi,
    OK my lack of knowledge is flashing in big neon letters, almost ready to crawl away and hide in shame.

    see comments below
    PHP Code:
    public class basic_bulk extends MovieClip{//Do I need this and with  a new name
            
    public var loader BulkLoader;
            public var 
    Video;//in which case do these need new names?
            
    public var counter int 0;

            public function 
    basic_bulk() {//or is it here I need a new name 

  7. #7
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Neither.

    The line with "public class basic_bulk" says that you are starting a new class. This must match the file name "basic_bulk.as".
    The line with "public function basic_bulk()" declares the constructor function for that class. This function is run when you call "new basic_bulk()". An actionscript class may have only a single constructor. The constructor name must match the class name.

    You want to add a class method, which will look like this:
    Code:
    public function loadMore():void{
      //stuff here.
    }
    You can then call your loadMore function on any basic_bulk instance you have.

  8. #8
    Senior Member
    Join Date
    Apr 2000
    Location
    Minneapolis
    Posts
    2,127
    Hi,
    well a bunch of errors sorted and I have my commented code back in.
    Flash says no errors but the extra loader also does not run.
    partA and partB load and are both stopped on frame 2.
    so the first loader is complete.

    could be close, could be delusional!
    I am uploading the .as file rather than post a big slab of code

    thanks heaps
    mark
    Last edited by mgason; 07-10-2009 at 05:20 PM.

  9. #9
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I think you should just be able to call the basic_bulkC method from your onAllItemsLoaded method.
    Code:
    public function onAllItemsLoaded(evt : Event) : void{
     trace("every thing is loaded!");
     var B : MovieClip = loader.getMovieClip("B")
     A.gotoAndStop(2);
     addChild(B);
     B.gotoAndStop(2);
     percent_mc.percent.text = 0;
     percent_mc.percent.visible = false;
     basic_bulkC(); //this kicks off the function which loads C.                   
    }

  10. #10
    Senior Member
    Join Date
    Apr 2000
    Location
    Minneapolis
    Posts
    2,127
    Oh The Joy!!!!!
    thanks for spending all this time on me.

    It loads from there.
    one small thing I noticed it says in loaderC
    A.gotoAndStop(3);
    B.gotoAndStop(3);

    they stay on frame 2 as set in the first loader

    Now problem 2.
    Rather than load it right away from there I want the button in partA to begin the load.
    PHP Code:
    //in partA.swf

        
    loadC_mc.addEventListener(MouseEvent.CLICKloadSectionC);
        
    loadC_mc.buttonMode true;
        
    loadC_mc.useHandCursor true;
        
        function 
    loadSectionC(e:MouseEvent):void{
    //??????????????
        

    Oh boy I thought of a problem 3
    how can I say in my partA movie listen for loaderC finsihing and if(loaderC is complete) do x.

    then I can leave you in peace and start implementing a bunch of loaders in my real movie.

  11. #11
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The first problem is probably caused by the fact that the B that you use in onAllItemsLoaded is not the same B referenced in onAllItemsLoadedC. You've redeclared the B variable, in a function local scope, which means that referencing B inside the function is not using the B property of the class. This means that the B used in onAllItemsLoadedC was never set, and is probably throwing a nullpointer error when you call gotoAndStop(3) on it, making the rest of the function not work. I don't know why A wouldn't go. You should turn on warnings (if they're not already) and use the debug test movie.

    Simple fix:
    Code:
    public function onAllItemsLoaded(evt : Event) : void{
     trace("every thing is loaded!");
     B = loader.getMovieClip("B"); //removed redeclaration so it will use class level B
     A.gotoAndStop(2);
     addChild(B);
     B.gotoAndStop(2);
     percent_mc.percent.text = 0;
     percent_mc.percent.visible = false;
    }
    In order for partA to kick off the load, it would have to have a reference to the loader. If A is dynamic (unless you have a custom class, it is), you can do that like this right after setting A:
    Code:
    A.loader = loader;
    A would then have to do something like this in the button handler:
    Code:
    loader.basic_bulkC();
    But this isn't great practice. A better alternative would be to have A dispatch a custom event and have your basic_bulk class listen for and react to it.

    A's button function:
    Code:
    function handleButton(e:Event):void{
      dispatchEvent(new Event("A_DONE"));
    }
    Relevant code in basic_bulk:
    Code:
    public function onALoaded(evt : Event) : void{
                trace("A is loaded!");
    			A = loader.getMovieClip("A")
                //var menu : MovieClip = loader.getMovieClip("theMenu")//getMovieClip -> returns a MovieClip object. Works on items with type "swf"
                addChild(A);
                A.addEventListener("A_DONE", loadC);
    }
    
    private function loadC(e:Event):void{
      basic_bulkC();
    }
    For problem 3, you can add a listener for loaderC's COMPLETE event and assign it a method in A. It would looks something like this:
    Code:
    loaderC.addEventListener(Event.COMPLETE, A.handleCDone);

  12. #12
    Senior Member
    Join Date
    Apr 2000
    Location
    Minneapolis
    Posts
    2,127
    Hi,
    I might actually leave you in peace for a while!!!

    I actually had do something in A when B was fully loaded
    so I did this..
    PHP Code:
    //in the .as file
     
    public function onAllItemsLoaded(evt Event) : void{
                
    loader.getMovieClip("B");
                
    A.gotoAndStop(2);
                            
    addChild(B);
                
    B.gotoAndStop(2);
                
    percent_mc.percent.text 0;
                
    percent_mc.percent.visible false;
            
                
    A.dispatchEvent(new Event("Base_Loaded"));//PUT THIS IN
        
    }

    //in the A swf
    this.addEventListener("Base_Loaded"baseDone);
        
        function 
    baseDone(e:Event):void{
            
    trace("base done!!");
        } 
    is that the right way to do it?

    I did come up with one more question, sorry.
    can I say addChild(B) from A when some stuff gets done there?
    OR should I dispatch an event from A when ready and listen in the .as to run a function adding B.

    I can not thank you enough, a major dam has been broken.

    mark

  13. #13
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    That is one way to do it, but it's a bit weird. Technically, since you are not using custom classes, that IS actually a bit safer than the way which immediately came to mind which is to just call the method on A. If you were using classes which actually defined the methods you need, that would be the way to go. In your case, what you've implemented is fine.

    I'm not sure I follow your latest question. A should never directly affect (alter properties, or call methods not defined by DisplayObjectContainer) its parent. Letting the kids boss the parent around is bad. Letting them ask nicely (dispatching an event) is good. So yeah, I'd suggest more event dispatching.

    OR, you can start using typesafe member properties so that you'll know it's safe to call certain methods from A, B, or whatever. That ends up being a lot more direct, but you should be aware of the principles of loose-coupling before doing so.

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