apache-flexurlbuttonhyperlinkcontextroot

Flex: How can I use the @ContextRoot in a Button or LinkButton


I'm trying to create a button that will simply link back to the context root. I noticed flex has a @ContextRoot attribute that appears to work only in certain cases. For example, if I try to use it in the following mxml:

<mx:Button label="Back to Root" click="navigateToURL(new URLRequest(@ContextRoot()), '_parent')"/>

I get the following error: Error: Attributes are not callable.

I can't seem to find this technique explained anywhere, is there another way?

Thanks for the help! Dave


Solution

  • Thanks to http://devgirl.wordpress.com/ for this solution! I think it is better than the Application.application.url solution:

    Use the HTTPService control:

    <mx:HTTPService id="home" url="@ContextRoot()"/> 
    

    And then in Action Script:

     navigateToURL(new URLRequest(home.url),"_parent");
    

    works like a charm!