简体   繁体   中英

Loading Flex resources relative to server root as opposed to .swf location

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM