Search code examples
actionscript-3swfaddress

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
}

Solution

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