| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|
#1 |
|
Obfuscated Coder
Join Date: Apr 2008
Posts: 681
|
I've recently acquired the Essential Actionscript 3.0 book and have been reading straight through in my spare time and on the bus. I'm currently about halfway through the chapter on Namepsaces; I have to admit that it's making my head hurt. I can understand the potential value of using a URL string to determine the country of origin of a site's visitor, but in other instances, I'm just not seeing it. It seems to me so far like it's basically a convoluted, roundabout way to control access to variable and function names.
I'm not seeing the value here. Can anyone give me some examples where the use of namespaces made their lives appreciably easier than had they done otherwise? Are there specific best practices involving them? If so, what makes them best practices aside from convention?
__________________
man.mask = mask_mc; Sigh. The AS3 version just doesn't look at nice as 'man.setMask(mask_mc);' |
|
|
|
|
|
#2 |
|
flash veteran
Join Date: May 2005
Location: Belgium
Posts: 899
|
I'm certainly no expert on namespaces and don't know if this is what they are really meant for, but I use them for 2 kinds of things:
1. as qualifiers for event listeners 2. for implementations of state machines Both can be done in lots of different (and maybe better ??) ways. I'll give an example of each ActionScript Code:
But to me the power of namespaces is more in the second usage. Let's say we have an button which in all states it reacts to the same events, but not in the same way. ActionScript Code:
Last edited by creynders; 06-21-2008 at 10:13 AM.. |
|
|
|
|
|
|
|
|
#3 |
|
Obfuscated Coder
Join Date: Apr 2008
Posts: 681
|
Thank you for the example. It seems sensible, and a lot more applicable to what I'm used to making than the KidsGame samples from the book where various classes define their own namespaces to (seemingly needlessly?) differentiate their similarly named methods.
__________________
man.mask = mask_mc; Sigh. The AS3 version just doesn't look at nice as 'man.setMask(mask_mc);' |
|
|
|
|
|
#4 |
|
as[org].addListener(this)
Join Date: Dec 2005
Location: LA, California
Posts: 838
|
State machine is a good example....
I basically use namespaces on properties/methods whenever I want a level of restriction comparable to internal, without the necessity of keeping the code all in the same package. I wouldn't waste too much time on namespaces for things like event handlers, because really those should just be private inside the class anyway. Instead of... ActionScript Code:
ActionScript Code:
Also, namespaces can used for xml nodes too. |
|
|
|
|
|
#5 |
|
Member
Join Date: Aug 2007
Location: Ascot, UK
Posts: 67
|
ZOMG. This is what I have been looking for.
(in 1960's household advert narration style) "At last, I can arrange my packages they way I feel it's logical to do, without concerns about how that affects internal access! Thank you, ASSERTNFAILURE!" You are the man/woman/androgyne, delete as appropriate. ![]()
__________________
www.visualharmonics.co.uk Last edited by NickZA; 12-13-2008 at 07:51 PM.. |
|
|
|
|
|
#6 |
|
Registered User
Join Date: Jun 2009
Posts: 1
|
Great post. I love the idea of assisting developers so they only seeing the methods via intellisense (of Flex Builder) for methods they need to see. I created a new demo to show that off. http://www.blog.rivello.org/?p=422
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Traversing Complex XML/Nested Namespaces | andrew444 | ActionScript 3.0 | 0 | 09-07-2008 08:37 PM |
| Namespaces issue | oxk4r | ActionScript 3.0 | 2 | 07-17-2008 12:54 PM |
| help with namespaces | jszpila | ActionScript 3.0 | 3 | 04-09-2008 08:59 PM |
| public namespaces | creynders | ActionScript 3.0 | 7 | 11-14-2007 02:13 PM |
| auto import namespaces | abeall | ActionScript 3.0 | 7 | 06-30-2006 04:36 PM |