Thanks for all of your response, it seems the problem was the onLoadInit event needed to be passed using the Delegate Class, rather than an inline function:

loadListener.onLoadInit = Delegate.create(this, mcLoaded);

Just in case this class is of any use to anyone here's my finished version.

Many thanks for everyone's suggestions, have a good weekend :)

Ali



////LoadChecker/////


class mc.LoadChecker {
        private var allLoadedFn:Function;
        public var itemsToLoad_ar:Array;
        private var itemsLoaded:Array;

        public function LoadChecker(a:Array, f:Function) {
                trace("loadchecker! created:"+a.toString());
                allLoadedFn = f;
                itemsLoaded = new Array();
                itemsToLoad_ar = a;             
                for (var i = 0; i<itemsToLoad_ar.length; i++) {
                        var arRef:Number = i;
                        var tempLoad:LoadObj = itemsToLoad_ar[arRef];
                        //array  contains custom objects taht contain url and 
mc vars
                        myLoader(tempLoad.targURL,tempLoad.targMC);
                }
        }

         function myLoader(str, mc) {
                trace("MY LOADER   loading file:"+str+"   mc:"+mc);
                var loadListener = new Object();
                loadListener.onLoadInit = Delegate.create(this, mcLoaded);
                var mcLoader = new MovieClipLoader();
                mcLoader.addListener(loadListener);
                //create holder inside of movie clip
var holder:MovieClip = mc.createEmptyMovieClip("holder", mc.getNextHighestDepth());
                mcLoader.loadClip(str, holder);
        }
        function mcLoaded(mcl:MovieClip) {
                itemsLoaded.push(mcl);
trace("itemsLoaded:"+itemsLoaded.length+" tload:"+itemsToLoad_ar.length);
                if(itemsLoaded.length==itemsToLoad_ar.length){
                        allLoadedFn.apply(null);
                }
        }
}
/////////////



On 31 Jan 2008, at 11:59, Matthew James Poole wrote:

Are you sure the method on the clips have initialised yet?

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Alistair
Colling
Sent: 31 January 2008 11:16
To: Flash Coders List
Subject: Re: [Flashcoders] AS2 Delegate event won't fire in my multi swf
loadclass

Thanks for your quick reply Glen, thing is, I want to allow the class to
trigger different functions that are passed to it and also to monitor
the progress of a number of SWFs. Sorry if I'm missing something here.
Cheers,
Ali




On 31 Jan 2008, at 10:55, Glen Pike wrote:

Hi,

   Why don't you just make your class the listener for the
MovieClipLoader and then implement the functions in your class?

   class LoadChecker {
      var mcLoader:MovieClipLoader;

      function LoadChecker() {
         mcLoader = new MovieClipLoader();
         mcLoader.addListener(this);
      }

      function myLoader(str, mc) {
         //...
         mcLoader.loadClip(str, mc);
      }


      function onLoadInit(mc...) {
         trace("loaded mc " + mc) ;
         //...doStuff.
         mcLoaded(mc);
       }

      function onLoadError(mc...) {
         trace("oops, there was an error ");
         //...carry on?
      }

      function mcLoaded(mc) {
         //...
      }
   }
     Put a trace in your onLoadInit function and also implement the
onLoadError function for the listener so you can see if they are
called - you can also stub out the other functions for MovieClipLoader

listeners and put traces in those to make sure it starts loading, etc.

   HTH

   Glen


ali drongo wrote:
Hiya, I've written a class that will load multiple SWFs and then call

a passed function when complete. My problem is that when all the
movies have downloaded the passed function won't fire. If anyone
could help me figure this that would be really helpful.Cheers, Ali



//
//  LoadChecker

// this class is passed am array and calls a function when all of the

objects in the array are loaded // // Created by Alistair Colling on

2008-01-30.
//  Copyright FPP Design Ltd 2008. All rights reserved.
//
// pass mcs to load and start loading

import mc.*;
import mx.utils.Delegate;


class mc.LoadChecker {
private var allLoadedFn:Function;
public var itemsToLoad_ar:Array;
private var itemsLoaded:Array;

 public function LoadChecker(a:Array, f:Function) {
trace("loadchecker! created:"+a.toString()); allLoadedFn = f;
itemsLoaded = new Array(); itemsToLoad_ar = a; for (var i = 0;
i<itemsToLoad_ar.length; i++) { var arRef:Number = i; var
tempLoad:LoadObj = itemsToLoad_ar[arRef];
myLoader(tempLoad.targURL,tempLoad.targMC);
}
}

 function myLoader(str, mc) {
trace("MY LOADER   loading file:"+str+"   mc:"+mc);
var loadListener:Object = new Object(); var tmpFun:Function =
mcLoaded; loadListener.onLoadInit =
function(target_mc:MovieClip):Void  { tmpFun.apply(null,
[target_mc]); }; var mcLoader:MovieClipLoader = new
MovieClipLoader(); mcLoader.addListener(loadListener);
//create holder inside of movie clip
var holder:MovieClip = mc.createEmptyMovieClip("holder",
mc.getNextHighestDepth()); mcLoader.loadClip(str,holder);

}
function mcLoaded(mcl:MovieClip) {
trace("a movie is loaded:"+mcl);
itemsLoaded.push(mcl);
if(itemsLoaded.length==itemsToLoad_ar.length){
trace("all movies are now loaded");
allLoadedFn.apply(null);
}
}
}
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




--

Glen Pike
01736 759321
www.glenpike.co.uk <http://www.glenpike.co.uk>
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

______________________________________________________________________
This e-mail has been scanned for viruses by the Virtual Universe e- mail
security system - powered by MessageLabs.
http://www.virtual-universe.net

______________________________________________________________________

The contents of this email are confidential and may be subject to legal privilege and protected by copyright. If you are not the intended recipient any use, copying or disclosure of this e-mail to any third party is strictly forbidden by the sender and we reserve all rights and remedies against any person or entity making any such unauthorised use. If you have received this email in error, please contact the sender immediately by telephone or return the email to the sender and then delete this email and any copies of it on your system. Virtual Universe Limited may monitor the contents of emails sent and received via its network for viruses and to ensure the lawful and authorised use of its systems. Virtual Universe Limited will not be held responsible for any damage caused by viruses which may be transmitted upon receipt of this email or the opening of any attachment thereto. Any views or opinions presented in this email are solely those of the author and do not necessarily !
 represent those of Virtual Universe Limited.

Virtual Universe Limited is a company established under the laws of England and Wales with registered number 03064568 and has its registered office at 1 Regent Street, London, SW1Y 4NW and principal place of business at 28-39 The Quadrant, 135 Salusbury Road, London NW6 6RJ, United Kingdom. It is registered for VAT in the United Kingdom with number GB877113217.


______________________________________________________________________
This e-mail has been scanned for viruses by the Virtual Universe e- mail security system - powered by MessageLabs. http://www.virtual- universe.net

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to