Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > General > Best Practices

Reply
 
Thread Tools Rate Thread Display Modes
Old 08-08-2008, 08:32 AM   #1
QuantumTiger
Member
 
Join Date: Jul 2008
Location: London
Posts: 64
Default Where best to put utility functions

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
QuantumTiger is offline   Reply With Quote
Old 08-08-2008, 10:15 AM   #2
pj-co
Site Contributor
 
Join Date: Jun 2008
Location: Brooklyn
Posts: 311
Default

I've always thought of utility classes as mostly static personally. Though I guess it kind of depends on what you mean by utilities.
pj-co is offline   Reply With Quote
Old 08-09-2008, 12:52 AM   #3
yell0wdart
jordanrift.com
 
Join Date: Sep 2007
Location: Phoenix, AZ
Posts: 297
Default

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.
__________________

bad developer

Jordan Rift

Last edited by yell0wdart; 08-09-2008 at 12:54 AM..
yell0wdart is offline   Reply With Quote
Old 08-09-2008, 01:36 AM   #4
Flash Gordon
rather be programming
 
Flash Gordon's Avatar
 
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
Default

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
Flash Gordon is offline   Reply With Quote
Old 08-11-2008, 10:50 AM   #5
QuantumTiger
Member
 
Join Date: Jul 2008
Location: London
Posts: 64
Default

Thanks guys - that's very helpful.
__________________
QT
www.quantumtiger.org
QuantumTiger is offline   Reply With Quote
Old 08-26-2008, 08:22 PM   #6
swivelmaster
Tasty donuts.
 
Join Date: Aug 2008
Location: Berkeley, CA
Posts: 24
Send a message via AIM to swivelmaster Send a message via Yahoo to swivelmaster Send a message via Skype™ to swivelmaster
Default

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.
swivelmaster is offline   Reply With Quote
Old 11-15-2008, 01:49 AM   #7
pj-co
Site Contributor
 
Join Date: Jun 2008
Location: Brooklyn
Posts: 311
Default

Quote:
Originally Posted by swivelmaster View Post
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.
$20 says FG has a class that grabs all the known properties of the DisplayObject and creates a new one with those properties
pj-co is offline   Reply With Quote
Old 11-16-2008, 04:50 AM   #8
pj-co
Site Contributor
 
Join Date: Jun 2008
Location: Brooklyn
Posts: 311
Default

Quote:
Originally Posted by pj-co View Post
$20 says FG has a class that grabs all the known properties of the DisplayObject and creates a new one with those properties
except that doesn't work for the graphics object

*smacks self on head *

I see what you mean swivelmaster. Interesting talk on adobe's JIRA site.
pj-co is offline   Reply With Quote
Old 12-20-2008, 10:46 PM   #9
NickZA
Member
 
NickZA's Avatar
 
Join Date: Aug 2007
Location: Ascot, UK
Posts: 67
Default

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:
except that doesn't work for the graphics object
could you explain?
__________________
www.visualharmonics.co.uk
NickZA is offline   Reply With Quote
Old 12-22-2008, 08:31 AM   #10
rawmantick
Pipty rupees only!
 
rawmantick's Avatar
 
Join Date: Jul 2007
Location: Novosibirsk, Russia
Posts: 1,713
Default

Quote:
except that doesn't work for the graphics object

*smacks self on head *

I see what you mean swivelmaster. Interesting talk on adobe's JIRA site.
Graphics can be copied separately either. Check copyFrom() method.
__________________
fly high
rawmantick is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT. The time now is 11:15 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.