0

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

Dave Meurer
  • 33
  • 1
  • 7
  • Are you trying to implement state management and link back to the initial state of the app w/o reloading the swf? – quoo May 13 '10 at 21:26
  • nope, I have an app that has more pieces to it than just the flex part - so, I'm basically going back to a homepage of sorts. Thanks for the response!! – Dave Meurer May 14 '10 at 13:15
  • BTW... I do have the context-root setup in my compile settings, so this works: ... just can't figure how to turn that into a link cleanly. – Dave Meurer May 14 '10 at 14:09

2 Answers2

1

Well, the cleanest way I found was to use a function in the script block, and not use @ContextRoot like:

private function goBacktoHompage():void
 {
  baseURL = Application.application.url;
  var tempUrl:String = baseURL.substr(7,baseURL.length);
  var tempUrlArr:Array = tempUrl.split("/");
  var contextRoot:String = tempUrlArr[1];
  var u:URLRequest = new URLRequest("/" + contextRoot);
  navigateToURL(u,"_parent");
 }

I would assume there is an easier way that could use @ContextRoot, so any other answers that don't use relative paths would be welcomed!

Thanks to these sites for the help:

http://blog.devsandbox.co.uk/?p=174

[Adobe help docs on passing arguments]

-Dave

Dave Meurer
  • 33
  • 1
  • 7
0

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!

Dave Meurer
  • 33
  • 1
  • 7