开发者

Is it possible to embed a Flex Assets Class in a CSS declaration?

开发者 https://www.devze.com 2023-01-29 07:08 出处:网络
I have an SWC which includes a number of Assets for my project.Within this SWC is also a static AS file which contains Class declarations for each image in the library.

I have an SWC which includes a number of Assets for my project. Within this SWC is also a static AS file which contains Class declarations for each image in the library.

For example, the SWF contains these images:

/assets/foo/bar/img1.jpg
/assets/foo/bar/img2.jpg

And it includes an AS file which is like this:

[Embed(source="/assets/foo/bar/img1.jpg")]
public static const IMG_1:Class;

[Embed(source="/assets/foo/bar/img2.jpg")]
public static const IMG_2:Class;

I would like to create a CSS declaration which uses these two images, but I don't want to embed the full path. Is it possible to do something like this?

<mx:Style>
    .mySampleStyle {
      开发者_开发知识库  upIcon:   Assets.IMG_1;
        downIcon: Assets.IMG_2;
    }
</mx:Style>

At the moment, this particular syntax is invalid -- I'm getting compile errors for the "." character in the style declaration.

Is there another way of doing this without embedding the path (e.g. upIcon: Embed(source="/assets/foo/bar/img1.jpg")) in the CSS?


As stated here in order to reference class member of type Class using ClassReference in CSS, you should used "_" instead of "." in the fully qualified name of the field you want to use.

In your example,

<mx:Style>
.mySampleStyle {
    upIcon:   ClassReference("Assets_IMG_1");
    downIcon: ClassReference("Assets_IMG_2");
}

should works.

0

精彩评论

暂无评论...
验证码 换一张
取 消