TwelvestoneFlash

Get URL of current SWF?


Sign in

  • Waiting for Godot ( 730 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 5.1 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.9 k posts )
    general front end design an...
  • Back End ( 9.7 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
Stickman
 
2009-04-22

I'm a bit rusty with my Flash these days, and I know this should be simple but...

I need to get the URL of the current SWF file, i.e. NOT the page that it's embedded in, but the path of the SWF itself. I'm driving myself crazy trying to work this one out, Google is no bloody help and it's the last piece of the puzzle for finishing off a project tht really should've gone live weeks ago.

Any help appreciated.

Storm
 
2009-04-22

_root._url

??

(as2 or as3?)

Stickman
 
2009-04-22

Of course it is.

slaps forehead

Thanks!

arigato
 
2010-11-29

I have a similar situation I think...

AS2:

varLoader = new LoadVars(); varLoader.load("content.txt"); varLoader.onLoad = function() { hero_holder.loadMovie(this.value1); } ...Where "value1" is a line (&value1=1.jpg&) in an external text file named "content.txt".

Basically the swf is getting uploaded to a dev environment with a generated folder name, and I have to give fixed URL paths instead of relative paths because for some reason the external files won't load in this environment without a fixed path, so effectively I have to find the swf's base url and preface the external file with that.

How a generated folder name would affect relative paths I have no idea, but this is the scenario as described to me.

How would I add _root._url in my code? If I'm completely on the wrong track, I'd appreciate any help at all.

Storm
 
2010-11-29

root url may not help because the CMS (or whatever system they're using...virtual domains in this case) may have the 'content' in a different place.....and whether the html page is virtual / dynamically generated or is a physical page.

What we do here is I make the back-end guys pass the dynamically generated page's path as a FlashVar and use that to reference imagery in a totally different place.

Do you put the TXT and the JPGs on the server? Do you control where they go in relation to the SWF? And where is the SWF in relation to the HTML page?

arigato
 
2010-11-29

I don't get to control anything, but it is definitely some sort of CMS issue. I really don't understand how uploading stuff to a generated directory would make the flash file unable to reference it correctly if the external content is getting uploaded to the same folder, and if it's not, just knowing the swf's url won't change that. > What we do here is I make the back-end guys pass the dynamically generated page's path as a FlashVar and use that to reference imagery in a totally different place. Please elaborate, this sounds very useful.

persist
 
2010-11-29

sounds like a heavyweight server is using programmatic paths for resource fetching, so the entire structure is likely virtualized by a content management product. You've found that using gets in such a system isn't very fun because you're actually asking the server to run a program in context of the path provided rather than simply return a data on the path. Virtualized paths can be moving targets using session ids and time dependent paths. Relative paths likely don't exist.

You may be able to use the path of the swf in context, but I doubt it. The swf may be sitting directly on the domain from its point of view. tough to say for certain with some of these server products.

:shrug:

I believe you'll be better of in the long run telling the server coders to add a set of uri paths in flashVars when the page renders.

//edit or what storm said.

Storm
 
2010-11-29

Well here's the crux of the issue...... the SWF's path is relative to the containing HTML page and not itself.

I make the .NET guys write JS into the page that calls the SWF as per below:

var flashvars = {serverName: "http://www.domain.com"}; // THIS RIGHT HERE...LOOK HERE

swfobject.embedSWF("myContent.swf", "myContent", "300", "120", "9.0.0","expressInstall.swf", flashvars);

As noted above in my subtle LOOK HERE, I make them generate a path using JS when they dynamically create the page at run-time. This should NOT be a Flash guy thing. This is a server guy thing to do.

And if your content is somewhere else still they could generate a: var flashvars = {serverName: "http://www.domain.com", contentPath: "http://www.otherserver.com/images"};

That's the EASIEST. But he may not exactly know what he's doing.....

but you guys go back to your code loop.....it threw me for a second there!! lol k

[edit] ari, try this..... set up your files in one folder....HTML, TXT, JPG, and SWF. Display everything you want and make sure it works.

ok? good?

NOW move the SWF to a 'content/' folder but leave the rest of the files and change only the path in the HTML to find the SWF. Even though you haven't changed the paths in the SWF nor the TXT, it should still find them because the SWF technically get pulled into the HTML and its relative paths. (I haven't confirmed this in AS3 though if its still that way but it always has been for AS2 and earlier.)

And you can always call me if you need to. This stuff is tough to type out.

arigato
 
2010-11-29

this line swfobject.embedSWF("myContent.swf", "myContent", "300", "120", "9.0.0","expressInstall.swf", flashvars); I understand "myContent.swf" is the swf loading in the page, the numbers are the height and width, what do "myContent" "expressInstall.swf" and flashvars refer to?

Storm
 
2010-11-29

swfobject.embedSWF("arismovie.swf", "id_attribute_ofsaidmovie", width, height, 9.0.0","expressInstall.swf", flashvars);

it shouldn't matter to you......he should be implementing your Flash SWF not you.

expressinstall is an SWF you can include to DL the player on the back-end for people. Ignore it.

flashvars is how you get JS to expose the variables for Flash to pick up as it loads.

var flashvars = { serverName: "http://www.domain.com", firstName: "Ari", position: "Doggie", value1: "1.jpg" };

In fact you don't really need your content.txt file if you don't want. Those values could be passed in to the FlashVars.

Say you're building a photo gallery, then your PHP server code would read the images in the folder and use JS to write them all out as variables instead of you listing them in your content.txt file.

Unloading work to the server guys is what I do best!! k I don't know HOW to do it but I know what works ideally for dynamic content.

lithium
 
2010-11-29

if you want every url that's ever referred to in your flash movie to be affected, you can add a "base" parameter to your embed and it'll automatically prepend that url to any url request, similar to the way base href works in html.

Otherwise, you can do something hacky like:

var parts : Array = this.loaderInfo.url.split("/"); parts.pop();

var baseURL : String = parts.join( "/" );

trace ( baseURL );

Storm
 
2010-11-29

Actually ExternalInterface will work in AS2 as well (if JS is on in the browser) and you could try reading the page's url from the browser.......

import flash.external.ExternalInterface; var pageURL:String = ExternalInterface.call('window.location.href.toString');

Techies, will that be accurate? The href reference on a virtual domain?

lith, is loaderInfo available for AS2 as well? I've never used that in AS2.

damn this is getting confusing!! hahaha

arigato
 
2010-11-29

I have a bunch of jpg files and a couple of text files - basically it's a complicated ad banner & since the nimrods in deployment can't figure out Flash at all I just build a rotator kind of thing. Why they don't just do a js rotator banner with embedded links is beyond me, but they want it to have buttons on it so you can scroll back and forth through the ads.

So yeah, it's not just passing variables, it's passing banner graphics & urls, too. I think your advice should be enough to get the deployment guys off my back, though. Technically I'm not supposed to be working on flash at all but unfortuantely I appear to be the only person in this entire company that knows how to use Flash on any level at all and the managers keep asking for it.

persist
 
2010-12-06

what ever happened with this?

arigato
 
2010-12-08

I passed it off to the frontend team. Apparently as long as the files I create work locally whatever problems there are with putting them on the server aren't for me to get involved with - it's not my department's project base so there's all sorts of budget and reporting issues if I work on it at that level.

persist
 
2010-12-08

Ah. I didn't know if there was a code solution hanging out there. Thanks!

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneFlash

Get URL of current SWF?