在动作脚本中创建一个带有图标的按钮 [英] Create a button with an icon in actionscript

查看:26
本文介绍了在动作脚本中创建一个带有图标的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Actionscript 在 Flex 中动态创建带有图标的按钮.

I want to create buttons with icons in Flex dynamically using Actionscript.

我试过了,没有成功:

var closeButton = new Button();
closeButton.setStyle("icon", "@Embed(source='images/closeWindowUp.png");

推荐答案

我找到了一个适合我的答案.在我的 .mxml 文件中,我为我将使用的图标创建了类:

I found an answer that works for me. In my .mxml file, I create Classes for the icons I will use:

// Classes for icons
[Embed(source='images/closeWindowUp.png')]
public static var CloseWindowUp:Class;
[Embed(source='/images/Down_Up.png')]
public static var Down_Up:Class;
[Embed(source='/images/Up_Up.png')]
public static var Up_Up:Class;

在我的应用程序的 Actionscript 部分,我在动态创建按钮时使用这些类:

In the Actionscript portion of my application, I use these classes when dynamically creating buttons:

var buttonHBox:HBox = new HBox();
var closeButton:Button = new Button();
var upButton:Button = new Button();
var downButton:Button = new Button();

closeButton.setStyle("icon", SimpleWLM.CloseWindowUp);
buttonHBox.addChild(closeButton);

upButton.setStyle("icon", SimpleWLM.Up_Up);
buttonHBox.addChild(upButton);

downButton.setStyle("icon", SimpleWLM.Down_Up);
buttonHBox.addChild(downButton);

这篇关于在动作脚本中创建一个带有图标的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆