cside23
cside23

Reputation: 23

How do I load dynamic image assets into adobe air

The app I'm working on displays four random images at one point. These four images come from a set of fifty images. If this was a standard Flex project I would just set the img.source property:

this.img1.source ="../assets/img/"+randomname+".png";`

This isn't working though, I'm getting a broken image. One other way to go about it is to load the image with a urlLoader, which is also not loading the image (unsurprisingly, given that it's a local asset)

loader = new Loader();
var urlReq:URLRequest = new URLRequest("../assets/img/"+randomname+".png");
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
loader.load(urlReq)

So this isn't working either, I'm thinking of loading all of the images into a swc and then linking the swc to the project. This is obviously not great because then all the assets are loaded into memory at runtime. Is there another way of doing this?

I'm hoping that I'm missing something really simple.

If the .swc solution is the best one, can someone point me in the right direction? I forget how that whole business works, as it's been a couple of years since I've worked with Flex/Flash.

Thanks in advance

Upvotes: 0

Views: 3265

Answers (2)

xastor
xastor

Reputation: 482

You should add your asset directories as "source" directories.

Then you should be aware of the fact that the contents of the asset directories will be copied to the root of your application. So when you have the image "assets/interface/bg.png" you should load it using new URLRequest("interface/bg.png").

Upvotes: 1

michael
michael

Reputation: 1160

You may try:

var urlReq:URLRequest = new URLRequest("assets/img/"+randomname+".png");

Upvotes: 0

Related Questions