Reputation: 21
I am trying to open url links from within the HTML component into the system browser.
I am using this method to create several HTML component child and all of them are added in a Vgroup.
public function addHtmlText(htmlValue:String):void {
var htmlData:HTML = new HTML();
htmlData.percentWidth = 95;
htmlData.htmlText = htmlValue
htmlData.horizontalScrollPolicy="false"
htmlData.verticalScrollPolicy="false"
chatCanvas.addElement(htmlData);
}
this is how I render the strait text link into a real link ( )
public function emoUrl(emoValue:String):String {
var urlRegex:RegExp = /(((http|ftp|https):\/\/){1}([a-zA-Z0-9_-]+)(\.[a-zA-Z0-9_-]+)+([\S,:\/\.\?=a-zA-Z0-9_-]+))/igs
var emoValue1:Array = emoValue.match(urlRegex);
if (urlRegex.test(emoValue)) {
emoValue = emoValue.split(emoValue.match(urlRegex)).join('<a href="'+emoValue1.toString()+'">'+emoValue1.toString()+'</a>')
}
return emoValue;
}
the problem is that since these are all individual HTML component elements and that a user can click on any one of them to open in the system browser.
currently, the link will open, but within the html component. I need it to be external.
I have found this on the internet that might help but I have no idea on hot to implement it for my needs.
htmlData.htmlLoader.navigateInSystemBrowser = true
thanks !
Upvotes: 2
Views: 2814
Reputation: 54
Create a URLRequest to the web page, and open it with navigateToURL :
var urlRequest:URLRequest = new URLRequest("http://www.adobe.com/");
navigateToURL(urlRequest);
Example loading a page upon click of a button with Flex MXML:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script>
<![CDATA[
import flash.net.navigateToURL;
protected function clickHandler(event:MouseEvent):void
{
navigateToURL(new URLRequest("http://www.adobe.com"), "_blank");
}
]]>
</fx:Script>
<s:Button label="Open page"
click="clickHandler(event)" />
</s:Application>
navigateToURL():
Opens or replaces a window in the application that contains the Flash Player container (usually a browser). In Adobe AIR, the function opens a URL in the default system web browser.
Parameters
request:URLRequest — A URLRequest object that specifies the URL to navigate to. For content running in Adobe AIR, when using the navigateToURL() function, the runtime treats a URLRequest that uses the POST method (one that has its method property set to URLRequestMethod.POST) as using the GET method.
window:String (default = null) — The browser window or HTML frame in which to display the document indicated by the request parameter. You can enter the name of a specific window or use one of the following values:
"_self" specifies the current frame in the current window. "_blank" specifies a new window. "_parent" specifies the parent of the current frame. "_top" specifies the top-level frame in the current window. urlRequest():
Creates a URLRequest object. If System.useCodePage is true, the request is encoded using the system code page, rather than Unicode. If System.useCodePage is false, the request is encoded using Unicode, rather than the system code page.
Parameters
url:String (default = null) — The URL to be requested. You can set the URL later by using the url property.
Upvotes: 2