Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 10-30-2009, 09:43 PM   #1
kcreation
Registered User
 
Join Date: Oct 2009
Posts: 6
Default Disabling Links and/or Redirecting Links in HTMLLoader

Here is some helpful code for disabling and redirecting links in the HTMLLoader:

Code:
import flash.html.*;
import flash.net.URLRequest;
import fl.controls.UIScrollBar;
import fl.controls.ScrollBarDirection;
import fl.events.ScrollEvent;

//set the url of the page we want to load
var url:String = "http://www.actionscript.org";

//create a new htmlloader object
var htmlObj:HTMLLoader = new HTMLLoader();
htmlObj.width = stage.stageWidth;
htmlObj.height = stage.stageHeight;
htmlObj.load(new URLRequest(url));
addChild(htmlObj);

//hide loader until the links have been changed
htmlObj.visible = false;

//setup listener to modify html through javascript after loading
htmlObj.addEventListener(Event.COMPLETE, htmlLoaded);
function htmlLoaded(event:Event):void {
	var hLdr:HTMLLoader = event.target as HTMLLoader;
	//setup redirect function
	htmlObj.window.redirectLink = redirectLink; 
	var numLinks:Number = hLdr.window.document.links.length;
	for(var i:int = 0; i < numLinks; i++) {
		hLdr.window.document.links[i].setAttribute("onclick","redirectLink(this.href, document.URL);return false");
	}
	trace("Links Disabled. Num:", numLinks);
	//show html loader since the link have been disabled
	hLdr.visible = true;
}

function redirectLink(hRef:String="", pageUrl:String=""):void {
	trace("hRef:", hRef, "   pageUrl:", pageUrl);
	//hide loader for new redirect
	htmlObj.visible = false;
	//new link
	var newUrl:String = "http://www.actionscript.org";
	//redirect link
	htmlObj.load(new URLRequest(newUrl));
}
kcreation is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:49 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.