I have a textfield that loads dynamic text from a random node in a xml. Some of these nodes contains hyperlinks.
Below is the code i'm using to setup and load StageWebView and go to the link, if the text i tap has a url
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.media.StageWebView;
import flash.geom.Rectangle;
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
var webView:StageWebView;
var swvRect:Rectangle;
var swvHeight:Number;
var swvY:Number;
var linkURL:String;
storyTxt.addEventListener(MouseEvent.CLICK, linkClicked);
function linkClicked(e:MouseEvent):void {
var idx:int = e.target.getCharIndexAtPoint(e.localX, e.localY);
trace("Tapped:",idx);
var tf:TextFormat = e.target.getTextFormat(idx);
if(tf.url != "" && tf.url != null) {
linkURL = tf.url;
trace(linkURL);
if(webView!=null){
return;
}
webView=new StageWebView();
webView.stage=this.stage;
webView.viewPort=new Rectangle(0,swvY,stage.stageWidth,swvHeight);
webView.addEventListener(ErrorEvent.ERROR,onError);
webView.addEventListener(LocationChangeEvent.LOCATION_CHANGING,onChanging);
webView.addEventListener(Event.COMPLETE,onComplete);
webView.loadURL(linkURL);
}
}
When i tap on the text that has a link, it opens both the mobile's browser [Safari] and the StageWebView. Is there a way of stopping the app switching over to the browser to open the link?
Thanks Daniel
You could try something like: