PDA

View Full Version : Get webpage Title from Actionscript


rafaelgp
02-06-2009, 04:59 PM
I have a business directory gorillaindex (http://www.gorillaindex.co.uk) which has 17 categories. For each category there is a map showing some markers that are feeded by a kml file (at the moment all the maps are feeded by the same kml file).

The point is that all the 17 maps are basically the same, with the only exception that each map loads a different kml file (arts.kml, restaurants.kml, etc...).

So I was wondering if it is possible to load a specific kml file depending of the title tag of the webpage. For example.

private function addMarkers(event:MapEvent):void
{
var pageTitle (*get somehow get the current HTML Title tag*);
var kmlmarkers:KMLLayer = new KMLLayer();
umap.addOverlay(kmlmarkers);
kmlmarkers.load(+pageTitle+".kml");
}
And I will name the the kml files with the corresponding title.

I am sure there are easier options to achieve what I want, but because the directory is built using php software I have some limitations. For example, I cannot put anything on www.gorillaindex.co.uk/arts because otherwise the webpage will not load.

Thanks for helping me in advance.

box86rowh
02-06-2009, 06:02 PM
why not pass the data about what map you want through the parameters on the swf.

in the embed code whereever you have the name of the swf like:

testFile.swf?code=art

and in the as code you could use parameters.code to get "art"

runawayprisoner
02-06-2009, 06:10 PM
If I'm guessing it right, you just want to use Flash to load the kml file, right? Anyway, long story short, try the ExternalInterface class.

Namely... you can create a JavaScript function to fetch the title of the document.

Something as simple as this should work:

JavaScript:
function getTitle() {
return document.title;
}

And your ActionScript is quite simple as well:


var title = ExternalInterface.call("getTitle");


Note: watch out for security errors. Better put the swf and the file calling it in the same directory in the same domain.

And note 2: won't work if you test the files locally, as reported by many. You need to use a real web server or a virtual web server to test this.

box86rowh
02-06-2009, 06:12 PM
but if they change the format or wording of the page title, the maps would break under that scenario. It is a much better and solid way to just pass the theme or category data into the swf through the querystring as I pointed out above