尝试用循环生成按钮,但 Icon 属性导致问题

发布于 2024-10-26 15:52:03 字数 796 浏览 4 评论 0原文

我正在尝试使用数组循环生成一个按钮,但我无法使图标样式和样式名称起作用:(

        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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋千易 2024-11-02 15:52:03

您不能将变量放入嵌入中,因为它是编译器的指令,而不是运行时解析。现在,您可以

  • 创建与您拥有的表情一样多的变量,然后让 N 个静态嵌入
  • 为接受 ImageLoader 的按钮创建您自己的皮肤并动态加载按钮内的图像
  • 预加载包含所有图像的 swf 并使用 emoticon.setStyle("icon", getDefinitionByName(smileys[x][0])) 其中 smileys[x][0 ] 是 Fl​​ash 库中笑脸的链接名称。

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 a Loader and load dynamically the image inside the button
  • preload an swf with all your images and use emoticon.setStyle("icon", getDefinitionByName(smileys[x][0])) where smileys[x][0] is the linkage name of the smiley in the Flash library.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文