That was really a great answer. You don't have to take the time to draw a class-diagram, that would be to much to ask for.
I understand what you are saying. And it would be really cool to have a really great Assets-manager class, it should be implemented natively ;) If now Flash could load and store files within the player, that would have been great. Now you can load into cache, and then hope that the cache is working when loading it the second time. Would have been great if you could load assets which you later frequently can use without requesting them again. / martin -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: den 28 oktober 2005 15:27 To: [email protected] Subject: Re: [Flashcoders] Singleton and Listeners is a bad combination I'd break this up into two classes. A font loader class and a font holder class, I personally wouldn't create a font holder class but more of an asset manager class that allows you to get access to assets anywhere in your application, you create an asset manager class, he is responsible for holding assets, fonts, audio, swfs etc... This is a singleton and its how you can get "assets" so if you need an asset you can say AssetManager.getInstance().getAsset("Arial"); Now your font loader class is not a singleton but is used by the asset manager to load fonts and then notify a caller that the font was loaded for example. AssetManager.getInstance.loadAsset(new FontLoader("Arial", "arial.swf"), Delegate.create(myMovieClip, onFrontLoaded)); the asset manager can call the Fontloaders' load method to load the font and then notify the "myMovieClip" when the font is loaded AND the asset manager will keep an internal reference to the loaded asset so others can get it later. Hope that makes sense, I can draw a class diagram if not. Grant ----- Original Message ----- From: Martin Klasson [EMAIL PROTECTED] To: Flashcoders mailing list [email protected] Sent: 10/28/05 6:32 AM Subject: RE: [Flashcoders] Singleton and Listeners is a bad combination > That is exactly what has crossed my mind. > I think I will have to do it just like that. > > I just finished up my singleton now, but it isn't really able to be a > singleton as you say. > > I will try to start from the beginning again. At least I do know what will be > implemented. > > Thanks for pushing me ;) > > / martin > > > > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Nils Millahn > Sent: den 28 oktober 2005 12:30 > To: Flashcoders mailing list > Subject: Re: [Flashcoders] Singleton and Listeners is a bad combination > > Hiya, > > I reckon that it would be a good idea not to make it a singleton but > create new instances every time. The fact that you are running into the > problem with listeners is a pretty clear indication that you require new > instances to be created for every use of the class - not really the > right scenario for a singleton. > > The FontLoader class could hold a static list of fonts that are already > loaded for internal reference - but the SWFs that are loading the fonts > don't need to know about that kind of logic - they simply need to know > that they can use the FontLoader class to load a font that they require. > > Hope that helps, > > Nils. > > > > Martin Klasson wrote: > > > > > > >Hi Coders. > > > > > > > >I got a class which I thought would be improved by using the Singleton > >pattern. And it does, until I am adding in the EventDispatcher. > > > >The problem is that my application will using the FontLoader.getInstance() > >at several places in different classes and files. > > > >The problem arises since you can set addEventListeners to the instance. > > > > > > > >If you in class A has: > > > >fntController = FontLoader.getInstance() > > > >fntController.addEventListener('onFinished', fontsLoaded) > > > > > > > >And in Class B you have the same as class A, just to state an example of the > >problem... > > > > > > > >The problem is that since FontLoader.getInstance() returns exactly the same > >instance everytime. So when class B fontsLoaded is called, the fontsLoaded > >is also called in class A. > > > >The problem is that even though you can use removeEventListener, you might > >not want do that since you might still want the fontsLoaded to be working in > >class A another time. > > > >One solution is that you in class A and class B doesnt have the same name > >for the function that is given in the addEventListener -but that doesnt seem > >like a neat solution to depend on that when several developers might write > >the same. > > > >As well as boring for the EventDispatcher used in the FontLoader to call > >listener-function which might not exist in the different scopes/classes > >where the FontLoader istance is. > > > > > > > >So I thought the best way would be to do the class ALL static, but the > >problem would still be the same with the listeners. > > > >I can only come up with one solution, and that is to do the usual, that you > >will have to instanciate the class. > > > > > > > >class A > > > >private var fntController:FontLoader = new FontLoader(); // now I can have > >listeners which just would listen to this instance. > > > >class B > > > >private var fntController:FontLoader = new FontLoader(); // now I can have > >listeners which just would listen to this instance. > > > > > > > >This will make them able to have listeners that wont interfere with each > >other. Is this the best solution, or do you know of any other solution that > >you think would suit this scenario? > > > >Listeners are incredibly great, and I am thinking on the Key-class, that has > >addListener, which is a static class and should suffer just as well as my > >FontLoader-listeners does. But somehow it doesnt fit the FontLoader. > > > >What do you think, any general advices? > > > > > > > >Singleton and EventDispatcher doesnt come in handy when you are having the > >getInstance() at several places in an application, or am I wrong? > > > >Thanks. > > > >/ martin > > > > > > > >------------------------------------------------------------------------ > > > >_______________________________________________ > >Flashcoders mailing list > >[email protected] > >http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > > > > > -- >  > > ----------------------------------------------------------------------- > Nils Millahn > Internet Solutions - Design and Development - Flash Specialist > > T: +44 (0) 7909 528 617 > E: [EMAIL PROTECTED] > W: www.hub124.co.uk > > ======================================================================= > Notice of Confidentiality. > > This transmission is intended for the named recipient only. It contains > information which may be confidential and which may also be privileged. > Unless you are the named addressee (or authorised to receive it for the > addressee) you may not copy or use it, or disclose it to anyone else. > > It is the responsibility of the recipient to ensure that the forwarding, > opening or use of the e-mail (and any attachment) will not adversely > affect their system or data. Please carry out appropriate virus checks. > ======================================================================= > > > _______________________________________________ > Flashcoders mailing list > [email protected] > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > _______________________________________________ > Flashcoders mailing list > [email protected] > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list [email protected] http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list [email protected] http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

