Skip to main content
Known Participant
March 2, 2010
Answered

Is there a way to get a relative url from a ._url call?

  • March 2, 2010
  • 1 reply
  • 508 views

Basically I have some movie clips with external images that were placed in them with a MovieClipLoader. I want these clips to toggle the image they're showing when clicked. However, the only way I know how to tell each image is loaded in them is by way of their ._url method (basically each click will return the url of the image and if it's the url for the current image, I'll place the alternate image in there). However, that gives me an absolute URL. I could use this for prototyping, but once it's deployed, it won't do any good to match it with my local testing url; I need to use a relative url, just like when I originally used the MovieClipLoader to place the images.

If that can't be done, is there a way to return the current url that the swf is playing from? That way I can put that into a variable that I can use for evaluating the source url to know which image should be in the movieclip whenever it's clicked.

This topic has been closed for replies.
Correct answer kglad

you can use the flash string methods to extract the part of the _url you want.  for example, if you want the file name on a server that uses the "/" directory delimiter, you can use

targetMC._url.substr(1+target_mc._url.lastIndexOf("/"))

1 reply

ankhcommAuthor
Known Participant
March 2, 2010

I found another way to get the end result I wanted. Knowing the answer to this would still be useful though.

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
March 2, 2010

you can use the flash string methods to extract the part of the _url you want.  for example, if you want the file name on a server that uses the "/" directory delimiter, you can use

targetMC._url.substr(1+target_mc._url.lastIndexOf("/"))

ankhcommAuthor
Known Participant
March 3, 2010

Ah, that solution is far more elegant than what I did!

I ended up splitting the URL into an array, then using some expressions to extract what I wanted. Maybe I should take more time to learn the basics before getting too creative heh.