SWFAddress, writing a switch/case for more than one level deep?

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
}

Answers


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();
} ...

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.


Need Your Help

Can't install PHPREDIS on PHP7 with Ubuntu 14.04

ubuntu-14.04 php-7 phpredis

I'm using PHP7 on ubuntu 14.04. Here is my PHP version information from terminal(using command PHP -v).