Handy Flash Domain Reading

“How can a Flash file see the address of the page its on?”

Get asked that one quite a lot. I’ve put some thought into it and have begun toying with a few ideas.

The other day I was browsing the Class libraries (like you do) and I stumbled across two methods of getting domain information inside Flash, both examples will use the following url as their content path:

https://www.davidmillington.net/news/index.php

In the HTML the top page swf header has its full address that looks like this:

https://www.davidmillington.net/shared/swf/navi.swf?sec=news

i.e:

<object type="application/x-shockwave-flash" data="/shared/swf/navi.swf?sec=news" width="770px" height="76px">
<param name="movie" value="/shared/swf/navi.swf?sec=news" />
</object>

Inside Flash we can use the LocalConnection class to get the domain name:

var domain_lc:LocalConnection = new LocalConnection();
trace(domain_lc.domain());
/* traces www.davidmillington.net */

The second method is simply:

trace(_root._url);
/* traces https://www.davidmillington.net/shared/swf/navi.swf?sec=news */

Each time you load a Flash movie its _url property gets set to the address it was loaded from.

Im not sure what would happen if you used server side path rewriting to do something like

https://www.davidmillington.net/news/shared/navi.swf

as the path used in the Flash objects data attribute. If that was seen inside Flash instead of its real location then it means you could easily parse that string to get the page name “/news” and then the real path “/shared/navi.swf”. Then its just a case of using “?sec=” + pagename in the rewrite system. Like I said though, without testing it I’m not sure which address it will see.

I’m going to do a test with a few http headers and see what I get. The most promising idea so far is to capture all requests for .swf files and then append the url of the page that requested it via the HTTP_REFERER header. I’m not sure if that will include the actual page name so that’s why this is a test.

Comments: None so far...be the first!

Leave a reply

Your email address will not be published. Required fields are marked *

There’s so much wisdom in here, I can’t find anything!

— Shifu, Kung Fu Panda 3