Reputation: 13258
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"
}
But how is it possible to replace these lines
folderOpenIcon="@Embed(source='assets/images/test.png')"
folderClosedIcon="@Embed(source='assets/images/test.png')"
defaultLeafIcon="@Embed(source='assets/images/test.png')"
with
folderIcon
? Does someone know this? Or should / can I use stylesheets?
Thanks a lot in advance & Best Regards.
Upvotes: 3
Views: 2186
Reputation: 39408
Embedding happens at compile time; not at run time. You can't embed an element using a set method.
Here is some info about embedding assets, such as PNGs in Flex:
http://livedocs.adobe.com/flex/3/html/help.html?content=embed_4.html
[Embed(source="assets/images/test.png")]
[Bindable]
public var folderIcon:Class;
And you can use it like this:
folderOpenIcon="{folderIcon}"
folderClosedIcon="{folderIcon}"
defaultLeafIcon="{folderIcon}"
Upvotes: 1
Reputation: 4340
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
}
}
Upvotes: 2
Reputation: 13258
I can do it with stylesheets. You can put in a
styleName="myButton"
and the via Stylesheets:
<mx:Style>
.projectButton {
icon: Embed("assets/images/test.png");
}
</mx:Style>
(also possible is an external stylesheet).
Upvotes: 0