Skip to main content
Participant
March 20, 2008
Question

Can I read the current url with AS3?

  • March 20, 2008
  • 5 replies
  • 675 views
I was working on a project and was wondering if it is possible to read the current URL and adjust the positioning of an item in my Flash Object based on that.

Example:
I click a link and load "thesite.com/page_15.html"


I store that URL in a variable and write an if, then, else statement that reads the variable and decides what myPosition is.

When my movie loads I state:
myObject.y==myPositionY
myObject.x==myPositionX

Thanks for the help, moving to ActionScript 3 has been a blast so far.
This topic has been closed for replies.

5 replies

Participating Frequently
March 21, 2008
I haven't integrated JavaScript with flash since AS2, but you should be able to pass in the url if you are embedding your swf in the HTML page using JavaScript.

See - http://blog.deconcept.com/swfobject/

In JavaScript you can use:

window.location

to get the page url.

Paste the following into the address bar whilst on this page and you should be alerted with the current page location (including get variables):

javascript: alert(window.location);

Lookup window.location on Google for more info.
Participant
March 23, 2008
Thanks, I'll see where I can get with this and post a follow-up in a couple days.
Participating Frequently
March 20, 2008
That was me - had to go to lunch.
Participating Frequently
March 20, 2008
That's the best you can do in Flash, otherwise you can use JavaScript to pass the page url to Flash.
Participant
March 21, 2008
Could you elaborate more on using javascript with Flash? I pick up techniques quickly, I've never tried it yet. Thanks
Damon Edwards
Inspiring
March 20, 2008
Im not positive on this one, but I think that'll give you the url to the swf??...? Or whatever is being loaded into the player.. I would tend to use php to capture the current url and send in to your document via FlashVars.

$_SERVER["SERVER_NAME"] to get the domain

$_SERVER["REQUEST_URI"] to get the page requested, ie, page_15.html


ps. that was a quick visit James, if that was you!
Participating Frequently
March 20, 2008
trace(this.loaderInfo.url);