?
Solved

Need to "intercept" URLRequests from pages loaded into HTMLLoader

Posted on 2008-10-04
3
Medium Priority
?
1,084 Views
Last Modified: 2013-11-11
Hi there.

I have an urgent request. As part of an AIR browser I am building for a project, I need to intercept HTTP requests (via clicked hyperlinks, submitted forms, etc.) made from pages I have loaded into an HTMLLoader component, in order to have my browser decide how to open those requested pages. The difficulty is nicely summed up by the feature request at http://bugs.adobe.com/jira/browse/SDK-12168. Once I've opened an html page in an HTMLLoader, I need navigation within that HTMLLoader to be "overridable". The problem is that the location_change event appears to be sent after the HTTP request is transmitted, and not before. On top of that, once the request is transmitted, calls to cancelLoad() fail. According to the 2nd contributor to the feature request above, this behaviour is "fixed"; however, I have been unable to get this to work.

Initially, i was working in Flash CS3, but when thwarted, attempted the same thing in Flex, with the same result. This doesn't really surprise me, since the problem would appear to be with when AIR transmits the location_change event...

If anyone has come up with a workaround for this issue (or can simply demonstrate to me how I should do this) then I would hugely appreciate it, because time is growing short for me now! Ideally, I'd like to build this entirely in Flash, but if this isn't possible, then Flex it is. It seems like such a simple request, and is definitely how the location_change event SHOULD act (in my opinion), that I can't believe this isn't going to be possible. :o(

Terry
0
Comment
Question by:tcattermole
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
evcr earned 2000 total points
ID: 22931986
Seems ok here, maybe I've got the wrong end of the stick.
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
	<![CDATA[
import mx.controls.Alert;
public var storedUrl:String = "http://www.google.co.uk";
 
function locChangeHandler(e:Event) {
	if (htmlbox.location != storedUrl) {
		htmlbox.location = storedUrl;
		//Alert.show('Blocked');
	}
}
]]>
</mx:Script>
	<mx:HTML click="" x="70" y="81" width="763" height="539" location="{storedUrl}" id="htmlbox" locationChange="locChangeHandler(event)" />
	<mx:Button x="698" y="37" label="Bbc" click="htmlbox.location='http://www.bbc.co.uk'"  change="Alert.show('change');"/>
    <mx:Button x="798" y="37" label="Google" click="htmlbox.location='http://www.google.co.uk'"  change="Alert.show('change');"/>	
</mx:WindowedApplication>

Open in new window

0
 

Author Closing Comment

by:tcattermole
ID: 31503010
evcr

I've accepted the answer - thank you! - but I have a further comment/question you might have some insight into? I'll post it once this is closed.

Thanks!
Terry
0
 

Author Comment

by:tcattermole
ID: 22932898
Hi evcr

Thanks for the solution. I have been remiss about getting back here and updating this question (sorry!), because I did work out ALMOST this answer myself. This stops the change of location, but does so by refreshing the current location (the state/DOM of which might have changed in the meantime, so that's not ideal). When searching for help though I came across a developer who noted that if an attempt to find a new location fails, the load silently fails. No error message. So my solution has been to try and load something like "httpy://nonsense_url" in response to a location change, and this has worked perfectly. Still seems astonishing, though, that a simple cancelLoad() does not work?

But this leads to a further question, which would make this solution even more useful to me. All one "intercepts" here is the URL. Any ideas re how to intercept the entire HTTP Request. By which I mean, including POST data (if any)?

Thanks in advance!
Terry
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question