本文介绍了使用包含文件名的字符串变量嵌入图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在 mx:tree 中嵌入图像:

I try to embed images in a mx:tree:

<mx:Tree labelField="name" id="tree"
    folderOpenIcon="@Embed(source='assets/images/test.png')"
    folderClosedIcon="@Embed(source='assets/images/test.png')"
    defaultLeafIcon="@Embed(source='assets/images/test.png')">
</mx:Tree>

这工作正常,但我将使用字符串变量嵌入图像.

This works fine, but I will embed the images with a String variable.

我有一个变量和一个函数

I have a variable and a function

[Bindable]
private var folderIcon:String;

public function setIcon(icon:String):void {
    folderIcon = icon; // "assets/images/test.png"
}

但是如何替换这些行

folderOpenIcon="@Embed(source='assets/images/test.png')"
folderClosedIcon="@Embed(source='assets/images/test.png')"
defaultLeafIcon="@Embed(source='assets/images/test.png')"

folderIcon

?有人知道吗?或者我应该/可以使用样式表吗?

? Does someone know this? Or should / can I use stylesheets?

提前致谢&最好的问候.

Thanks a lot in advance & Best Regards.

推荐答案

我不太确定您为什么需要它.无论如何,如果您尝试在 AS3 中嵌入图像,您应该执行以下操作

I am not really sure why you need that. Anyway if you are trying to embed images in AS3 you should do the following

class MyClass{

[Embed(source='assets/images/test_open.png')]
private static var folderOpenIcon:Class;

[Embed(source='assets/images/test_close.png')]
private static var folderClosedIcon:Class;

[Embed(source='assets/images/test_default.png')]
private static var defaultLeafIcon:Class;

[Bindable]
private var fodlerIcon:Class

public function setIcon(iconClass:Class):void {
    folderIcon = iconClass:Class;
}

private function testIcon():void{
    setIcon(defaultLeafIcon);
    // or
   setIcon(folderOpenIcon);
    // etc

}
}

这篇关于使用包含文件名的字符串变量嵌入图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 04:32