尝试用循环生成按钮,但 Icon 属性导致问题
我正在尝试使用数组循环生成一个按钮,但我无法使图标样式和样式名称起作用:(
for (var x:int = 0; x < smileys.length; x++ ) {
var emoticon:Button = 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;
}
我也尝试将其插入循环中,但它也不起作用:
[Embed(source="smileys/"+smileys[x][0]+".png")] // fb doesn't like that
var buttonIcon:Class;
emoticon.setStyle("icon", buttonIcon);
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:Button = 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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能将变量放入嵌入中,因为它是编译器的指令,而不是运行时解析。现在,您可以
Image
或Loader
的按钮创建您自己的皮肤并动态加载按钮内的图像emoticon.setStyle("icon", getDefinitionByName(smileys[x][0]))
其中smileys[x][0 ]
是 Flash 库中笑脸的链接名称。You can't put variables in an embedding since it's an instruction for the compiler, not a runtime resolution. Now, you can either
Image
or aLoader
and load dynamically the image inside the buttonemoticon.setStyle("icon", getDefinitionByName(smileys[x][0]))
wheresmileys[x][0]
is the linkage name of the smiley in the Flash library.