We help IT Professionals succeed at work.

How to I link to a named anchor in flex / air?

jdunneuk
jdunneuk used Ask the Experts™
on
Hi Guys,

I am trying to open a pdf on a certain page using navigatetourl in flex, however i cannot get the # symbol to go in to the url its been stripped,

John
var urlRequest:URLRequest = new URLRequest("/assets/guide.pdf");

				

				
				if(mode =="Manaul")
				{	
					urlRequest.url="/assets/manaul.pdf";

				}

				 var variables:URLVariables = new URLVariables();

				variables.stuff = "page="+this.page.toString();
				urlRequest.data = variables;
				navigateToURL(urlRequest,"_blank");

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You can't use URLVariables for PDF commands, See below how to go about it:

var urlRequest:URLRequest = new URLRequest("/assets/guide.pdf");

                        if(mode =="Manaul")
                        {      
                              urlRequest.url="/assets/manaul.pdf";
                        }
                        
                        urlRequest.url += "#" + "page=" + this.page.toString();
                        navigateToURL(urlRequest, "_blank");


In short if you want to open specific page in PDF, it should be like (for e.g.) guide.pdf#page=5 (5 is page number)

Author

Commented:
Hi,

Yeah tried that, didnt work for some reason, it striped it out and just called /assets/guide.pdf" however when I debug it shows the # in it as it should be.

Just a side not i am using AIR.

John
The only way I see is using absolute URL.

Whether it's a web url or local file url, if you'll use absolute path than you'll be able to provide page number.

FOR E.G:

var urlRequest:URLRequest = new URLRequest("file:///D:/project/assets/guide.pdf");

                        if(mode =="Manaul")
                        {      
                              urlRequest.url="file:///D:/project/assets/manaul.pdf";
                        }
                       
                        urlRequest.url += "#" + "page=" + this.page.toString();
                        navigateToURL(urlRequest, "_blank");

if it's a web url than provide absolute web url in URLRequest like, "http://www.mydomain.com/assets/guide.pdf"

Author

Commented:
Worked perfectly, thank you so so so so so so much