PDA

View Full Version : Importing External Assets Dynamically?


revlob
07-24-2009, 06:20 PM
I'm trying to write a gallery application in Flash (AS3). It uses a simple XML document to specify a series of images like this:


<Gallery name="foo">
<Image src="foo/1.jpg" />
<Image src="foo/2.jpg" />
</Gallery>
<Gallery name="bar">
<Image src="bar/1.jpg" />
<Image src="bar/2.jpg" />
</Gallery>


I have a class which parses the XML and displays the images (which sit locally, relative to the .swf file accordiing to the 'src' properties in the XML above) in a UILoader instance. This works great until I move the .swf file somewhere else, as the images aren't part of the compiled file, and obviously it's now looking for them in the wrong place.

I understand that you can use [Embed] to embed assets into your code (this is how I include the XML document), but I can't use it to embed the images. Is there a way I can embed the images in my flash document, and address them using the src values obtained from my XML?

TomMalufe
07-24-2009, 06:52 PM
You don't need to embed anything (not even the XML).

Use... wait a second. You're using a UILoader component? I've never worked with that before. I always just load stuff manually.

Why don't you just put the images in your Library? Instead of using the XML document, you can just make an array of the images and cycle through them on stage.

henke37
07-25-2009, 02:06 PM
Just learn about how urls works properly, you need an absolute url, nothing more.

ASWC
07-25-2009, 03:17 PM
absolute url will bring another set of problems: sandbox security.

The path in your xml can be changed to reflect any change. So just cahnge the paths in your xml, that's what external xml is for.

henke37
07-25-2009, 08:10 PM
Uhm, absolute url or not, if the file is on a specific server, you get sandbox issues no matter what url you use to access it. Sandbox issues are easy to fix when you are the one responsible for the remote host.

ASWC
07-25-2009, 08:24 PM
hum, that is not true. Obviously when you use relative urls you are on the same server and relative urls are not tied to security sandbox. Absolute urls are different, they always have to pass a security sandbox check whether they are or not on the same server.

henke37
07-25-2009, 10:29 PM
Actually, there are relative urls that can point at a different server. Also, you never said what the url is relative to to begin with. It could be relative to an url at another server.

ASWC
07-25-2009, 11:41 PM
Actually, there are relative urls that can point at a different server. I'd like to see an example of that. I never heard of relative url being able to point to other servers. Really looking forward to the example you are gonna post for me and the forum!

henke37
07-26-2009, 12:54 AM
//www.actionscript.org/ is a relative url.

revlob
07-26-2009, 05:36 PM
What I was hoping to be able to do is take the 'src' values from the XML file, and pass them to UILoader which then displays the image. The images I'd like to embed in the final flash file. If I import the images and add them to my library, how do I refer to them when setting UILoader's source parameter?