Howto embed images in Actionscript 3 / Flex 3 the

2019-01-17 16:54发布

I'm creating a game where a lot of images are being used in Actionscript / Flex 3 (Flash). Now that I've reached the designer stage, I have to work out a structural way of using embedded images (which have to be manipulated with rotation, color, etc.).

Unfortunately, after investigating a bit, it looks like you have to manually embed images before you can use them. I currently have it setup like this:

Resource.as class file:

package
{
    public final class Resource
    {
        [Embed (source="/assets/ships/1.gif" )]
        public static const SHIPS_1:Class;
    }
}

So, just for one ship I so for have to:

Put the image in the correct folder with the correct name Name it in the same way in the Resource.as file Create the constant with the same name in the Resource.as file

Even though this should all be possible by simply putting the file in a specified folder.

To make things even worse, I still have to call it using:

var test:Bitmap = new Resource.SHIPS_1();

There must be better ways to handle resources when creating very huge applications? Imagine I need thousands of images, this system simply wouldn't fit.

12条回答
We Are One
2楼-- · 2019-01-17 17:30

Good idea, lhk

That is nice solution like Source-Engine with vtf and vmt vtf = image vmt = script ( like xml or javascript )

Good i would like to suggest for TexturePacker, TexturePath or TextureTarget :P

Thanky ou for tip.

For example: mytexture.js:

xml or javascript:

function mytexture(){ basedir = "/assets/mytexture.png", normalmap = "/assets/mytexture_bump.png", normalcube ) [ 1, 1, 1 ] };

I don't think because default texture gets error somewhere mytexture.png doesn't exists than it happens again :)

[Embed(source="../assets/editors/error_texture.png")] public static const ERROR_TEX:Class; ...

How do i know because Actionscript 3 should "read" to javascript like jsBirdge or ExternalInterface.call();

Is it possible?

查看更多
爷的心禁止访问
3楼-- · 2019-01-17 17:33
[Embed (source="/assets/ships/1.gif" )]
    public static const SHIPS_1:Class;
查看更多
爷、活的狠高调
4楼-- · 2019-01-17 17:36

instead of

var test:Bitmap = new Resource.SHIPS_1();

Use

myImage.source = Resource.SHIPS_1;

The embedding is correct. :D the way you use it is wrong :)

Adrian

查看更多
对你真心纯属浪费
5楼-- · 2019-01-17 17:36

It depends how big your individual images are but you could put them all in one image like a spritesheet. If you want to draw a particular ship use the correct xy offset in the image for that ship and use copyPixels to draw it to your bitmap.

查看更多
Animai°情兽
7楼-- · 2019-01-17 17:41

This is old but since I stumbled across it searching for something different I'll write here for future generations : )

I use a different approach. I create a swf movie with flash professional and import all graphics in it and then mark them all for "Export for ActionScript". Compile the swf and in your main project embed only the swf and access all the graphics through it...

I find this approach much more organized. Why write the whole resources class when you can make it by importing files right? ;)

查看更多
登录 后发表回答