I'm trying to generate a button with the loop of an array, but I can't make the icon style and the stylename work :(
for (var x:int = 0; x < smileys.length; x++ ) {
var emoticon:Butt开发者_如何学JAVAon = new Button();
var label:String = smileys[x][0];
emoticon.width = 24; emoticon.height = 24;
emoticon.x = positionX; emoticon.y = 0;
emoticon.styleName('buttonImg'); // doesn't work...
emoticon.setStyle("icon", "@Embed(source='smileys/"+smileys[x][0]+".png')"); // doesn't work
emoticonsGroup.addChild(emoticon);
positionX+= 24;
}
I also tried to insert this in the loop but it doesn't work neither :
[Embed(source="smileys/"+smileys[x][0]+".png")] // fb doesn't like that
var buttonIcon:Class;
emoticon.setStyle("icon", buttonIcon);
You can't put variables in an embedding since it's an instruction for the compiler, not a runtime resolution. Now, you can either
- create as many variables as smileys you have and then have N static embeddings
- create your own skin for a button which accepts an
Image
or aLoader
and load dynamically the image inside the button - preload an swf with all your images and use
emoticon.setStyle("icon", getDefinitionByName(smileys[x][0]))
wheresmileys[x][0]
is the linkage name of the smiley in the Flash library.
精彩评论