views:

2246

answers:

2

I have a large (700kb) Flex .swf file representing the main file of a site.

For performance testing I wanted to try and move it off to Amazon S3 hosting (which i have already done with certain videos and large files).

I went ahead and did that, and updated the html page to reference the remote .swf.

It turns out that Flash will load any resources relative to the .swf file accessing the resource - no matter what the root of the html page is. So my resources are now being loaded from the remote site (where they don't exist).

There are two obvious things I could do : * copy all my resources remotely (not ready for this since i'm just testing now) * add in some layer of abstraction to every URL that the .swf accesses to derive a new path.

I really want to flick a switch and say 'load everything relative to [original server]'.

Does such a thing exist or am I stuck loading everythin from the remote machine unless I fully qualify every path?

i want to avoid anything 'hacky' like : subclass Image and hack the path there

A: 

You could try specifying the base parameter of your SWF's embed/object tags. In theory it defines the base path that will be used to resolve relative paths for loading, but I don't know if it will work if the base value points to a different server from where the SWF is.

See the docs on embed/object params here. Scroll down to "base" at the middle.

If that doesn't work, another thing I've seen people do is to pass in a custom base path via flashvars. Then inside your SWF, you check if that base path is defined, and if so prepend it to relative URLs before loading.

fenomas
i tried adding 'base' and it doesnt seem to work - at least for SWFLoader it doesnt
Simon
+1  A: 

Append a slash before your urls, this should load relative to the domain instead of the current folder:

foo.load('/like/this/image.jpg')

This is a bit quick and dirty, feeding a "relative" url via a querystring (or the base parameter) would be way more flexible.

grapefrukt
This wouldn't work. He's saying that his SWF is on a different server than the HTML, and he wants to load relative to the server where the HTML is. Also, this would require him to change all his load statements, which is what he's asking how to avoid.
fenomas