views:

55

answers:

2

I'm using the following switch/case for SWF Address:

switch (e.value)
{
    case "/A" :
        function A();
        break;

    case "/B" :
        function B();
        break;

    case "/C" :
        function C();
        break;

    case "/" :
        break;

}

The problem is, when I am in any section (A, B, or C)...there is another level of links, say:

www.my-site.com/A/next-level-goes-here

www.my-site.com/A/something-else-in-the-A-level

www.my-site.com/A/third-thing-in-the-A-level

I would like to write a case for anything that happens nested inside of A, but how do I go about this?

function anythingNestedInsideOfA()
{
 // handle all the stuff inside of A section here
}
+2  A: 

Use a combination of if and substr:

var url:String=e.value;

if (url=="/A") {
 A();
} else if (url.substr(0,3)=="/A/") {
 anythingNestedInsideOfA();
} else if (url=="/B") {
 B();
} else if (url.substr(0,3)=="/B/") {
 anythingNestedInsideOfB();
} ...
Patrick
That is amazing, thanks!
redconservatory
Or split on "/" or "\"
TandemAdam
+1  A: 

I wouldn't use this type of architecture. From my point of view you should pass that url's tail into object that is responsible for that level. In this case you can handle "A" as you do it, then rip it off and pass rest into that object, where you show A's content... and so on in deep. Probably that's a more general and big topic for StackOverflow.

Pavel fljōt
this is funny because it's true...I'm rewriting the whole thing with a proxy class/controller right now...anything more than one-level deep seems to require some serious OOP work...
redconservatory