A different use for custom namespaces (1/2)

When namespaces were first introduced in Actionscript 3 I thought it was all pretty cool, but still I sort of had a difficult time thinking of actual use-cases.

What I initially would have liked to use custom namespaces for was to restrict access to certain properties/methods, to only be accessible for certain classes, in the way that private and protected enable you to — unfortunately there is no simple way of defining who can import your namespace, consequently rendering namespaces somewhat useless for this particular use-case.

Then some time ago it struck me that rather than defining new members with a custom namespace, that you could of course also enhance an existing method instead (I admit this might seem like a no-brainer, but it took me a while to bump into).

Let’s say you have a subclass that for regular (outside) usage needs to override a method in the superclass, but itself still needs to use the original (super-) method. You would probably just override the method in the subclass and use super.method() wherever you needed to use the original functionality.
Now let’s say that you need to make a subclass of your subclass, which would also require access to the original functionality in said method. All of a sudden super.method() will not work for you anymore.

Here’s where namespaces start coming in handy, while still simply overriding the method in the first subclass, you also implement a function with the same name but with your own namespace (for example “original”). Then whenever you need to call the original implementation you can call original::method(), regardless of how deep down in the inheritance-chain you are.

This is only one use-case, you could for instance also use this concept to work around the nasty ambiguous-reference bug you get (or used to get) when declaring a getter and a setter with different (native) namespaces.

To keep the focus on the above described concept I put the example-code in a seperate post, feel free to read on though.

Pathfinder & Organisms (AI)

As promised, here is the project experiment that I originally wrote the pathfinder algorithm for.

[kml_flashembed movie=”http://www.rubenswieringa.com/blog/wp-content/uploads/2008/pathfinderdemo06.swf” width=”400″ height=”375″ /]

Here’s how it works: ‘Organisms’ (the colored moving squares) are thrown into an infrastructure (a collection of connected points, i.e. the circle/star with connected dots). Each organism is assigned a certain destination-point within the infrastructure and carries with it a pathfinder (a polished version of the algorithm I posted about some time ago).

The pathfinder will figure out which points to travel (trial and error, guessing together a route to the assigned destination, see previous post) in order to reach the destination and will then tell its organism where to go.

When two organisms happen to travel the same connection (line between two points in an infrastructure) they will share and compare their knowledge about several of the paths they have traveled, this is visualised by both organisms becoming semi-transparent.

Spaces in Flex Actionscript-only project-names

Odd enough Flex Builder seems to hate it when you want spaces in the name of an Actionscript-only project:

Flex hates spaces, boo! :(

Here’s the rough guide to having spaces in your Flex Builder Actionscript-only project-names:

Compromise, boo! :(

Success, yay! :)

Kind of leaves me wondering, why all the fuss in the project-wizard if we can rename our projects in the navigator?

SVN misplaces my Flex project-files

A little over a week ago I made a post about Flex running old versions of my SWF. In a nutshell; Flex Builder 3 seemed to disregard any changes I made to the classes in my (Actionscript-only) project, and compile an SWF with older versions of the edited classes.

A few days later however, I concluded that it was not so much Flex 3 that was causing this issue, but rather Subversion.

Whenever I commited my changes to the Subversion-repository, the latest run-files (Main.swf and Main.html) from the bin-debug-folder on my harddisk would be commited to the html-template-folder in the repository.
As the html-template-folder serves as a template-depot (duh) for your Flex project, any files in it will be copied to the bin-debug-folder after compilation, effectively overwriting your freshly compiled SWF in this scenario.

Initially, this may go by unnoticed, as it will not be untill you update your project (or do a new checkout of the same project), that the run-files will be in the html-template-folder.

I work around this issue by commiting, updating, and removing the run-files from the html-template-folder, but I have yet to come across a proper solution for this problem. So any suggestions are more than welcome. The same goes for any explanation about this strange issue with Subversion..

UPDATE:Through the comments someone exlained where this issue is coming from, here’s a quote:

“your bin, bin-debug and html-template directories should *NOT* be committed to svn.

The problem you are having is that it’s copying all of the files in the html-template folder into the bin-debug folder, including the .svn hidden folder. SVN uses the .svn folder to determine where to put the files in the repository, so when you copy that folder, even though it’s in a different folder than when it started, the files will continue to be copied into the original location.”

UPDATE: ..also, if you would like to keep these folders in your SVN-repository nevertheless, here’s what you’ll need to do (credits go to Matthew for this one):

“Goto your project properties and pull up the Flex Compiler tab and the first checkbox you should see says somethign to the effect of “Copy non-embedded files to the output directory”, well uncheck that. This will allow you to keep your bin folders in the repo”

Flex 3, stop running the old version of my SWF!

UPDATE: Turns out it wasn’t so much Flex causing this ruckus, but rather Subversion:

I might’ve also have called this post “How many more times will I have to re-import my projects into Flex Builder 3!?”, this sucks..

Today I decided to work on a project of mine, so I pulled in the latest version from my Subversion-repository and opened up Flex Builder 3.
I started making some additions in classes etc. and eventually I ran the project. To my confusion the SWF I saw didn’t reflect any of the changes I’d made, so I made some bigger changes and still nothing changed in the generated SWF.

Long story short, Flex just kept showing me the SWF of an older version of the project. Nothing I did helped; I cleaned the project, refreshed it, renamed it.
Eventually I worked around this issue by deleting the project (not the files) from Flex Builder and creating a new one (same location and same main project-file).

Although I fixed this thing for now, my (fairly big) concern now is mainly about how many more times I will have to re-import my projects into Flex Builder 3..
My guess is that this has something to do with the compiler-cache and incremental compilation, but either way, I’d really appreciate it if the Flex Builder development-team would fix this.

Any suggestions are more than welcome. 🙁