| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|
#1 |
|
Member
Join Date: Jul 2008
Location: London
Posts: 64
|
Hi
In the AS3 project I'm working on at present I can see the need for a few (small) utility functions which several classes need access to. What's the best place to declare them? The options I've currently thought of are 1) to extend Sprite (eg to mySprite), place the utilities there and then make all the dependant classes extend mySprite or 2) to create a small utility class, create an instance in my main class and pass a reference to it to the objects which require it. Any options I've missed? Any thoughts on which method would be most efficient? Many thanks...
__________________
QT www.quantumtiger.org |
|
|
|
|
|
#2 |
|
Site Contributor
Join Date: Jun 2008
Location: Brooklyn
Posts: 311
|
I've always thought of utility classes as mostly static personally. Though I guess it kind of depends on what you mean by utilities.
|
|
|
|
|
|
|
|
|
#3 |
|
jordanrift.com
Join Date: Sep 2007
Location: Phoenix, AZ
Posts: 297
|
Personally, I'd create static classes within their own namespace or package to house all my utility methods (TextTools, EnumHelper, XmlTools, etc). That way you're not bloating your objects with a bunch of methods that they may or may not need. No need to inheritance-crazy just to extend functionality.
![]() Last edited by yell0wdart; 08-09-2008 at 12:54 AM.. |
|
|
|
|
|
#4 |
|
rather be programming
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
|
My utilitlies are all in a folder called utils. I have
XMLUtil ArrayUtil StringUtil quickCopy(DisplayObject) etc .......
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman |
|
|
|
|
|
#5 |
|
Member
Join Date: Jul 2008
Location: London
Posts: 64
|
Thanks guys - that's very helpful.
__________________
QT www.quantumtiger.org |
|
|
|
|
|
#6 |
|
Tasty donuts.
|
Please tell me what quickCopy(DisplayObject) does. There's a whole debate on Adobe's bug database about the lack of ability to do a real copy of any DisplayObject data.
In regards to the original question, static classes are where it's at. I also have some helpers that require instances to be made, but exist completely separately. One is for calculating file sizes, and includes instance variables for bytesLoaded and bytesTotal, and at any point you can get those values back converted to any size unit (byes, k, m, g, t, and p for the far future!). The conversion functions are still static though. |
|
|
|
|
|
#7 | |
|
Site Contributor
Join Date: Jun 2008
Location: Brooklyn
Posts: 311
|
Quote:
![]() |
|
|
|
|
|
|
#8 | |
|
Site Contributor
Join Date: Jun 2008
Location: Brooklyn
Posts: 311
|
Quote:
*smacks self on head * I see what you mean swivelmaster. Interesting talk on adobe's JIRA site. |
|
|
|
|
|
|
#9 | |
|
Member
Join Date: Aug 2007
Location: Ascot, UK
Posts: 67
|
Um, Is this turning into a thread on deep copying?
Always interested in what other people use, here's the most recent info I've found on that. http://www.richapps.de/?p=34 http://www.stimuli.com.br/trane/2007...ng-or-cloning/ @pj-co, Quote:
__________________
www.visualharmonics.co.uk |
|
|
|
|
|
|
#10 | |
|
Pipty rupees only!
Join Date: Jul 2007
Location: Novosibirsk, Russia
Posts: 1,713
|
Quote:
__________________
fly high |
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Selecting 1 of 12 functions by random | jost | ActionScript 2.0 | 7 | 11-01-2007 12:15 PM |
| modularizing into multiple .swf files and still sharing variables and functions | coolburn | ActionScript 3.0 | 1 | 08-25-2007 11:48 PM |
| Functions inside if | virruss | ActionScript 2.0 | 7 | 08-11-2007 01:06 AM |
| When to use named vs. anonymous functions | ironchefmoto | ActionScript 2.0 | 3 | 07-19-2007 12:12 PM |
| Functions inside Functions? | theone27 | ActionScript 2.0 | 2 | 07-05-2007 09:30 PM |