Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache flex 在actionscript中创建带有图标的按钮_Apache Flex_Actionscript 3 - Fatal编程技术网

Apache flex 在actionscript中创建带有图标的按钮

Apache flex 在actionscript中创建带有图标的按钮,apache-flex,actionscript-3,Apache Flex,Actionscript 3,我想使用Actionscript在Flex中动态创建带有图标的按钮 我试过了,但没有成功: var closeButton = new Button(); closeButton.setStyle("icon", "@Embed(source='images/closeWindowUp.png"); 我想你会把它加入舞台 此外,我认为您的嵌入缺少一个接近的报价/参数 closeButton.setStyle("icon", "@Embed(source='images/closeWindowU

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

我试过了,但没有成功:

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

我想你会把它加入舞台

此外,我认为您的嵌入缺少一个接近的报价/参数

closeButton.setStyle("icon", "@Embed(source='images/closeWindowUp.png");
应该是:

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

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

// 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部分中,我在动态创建按钮时使用以下类:

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);

错误在引号中,
@Embed
周围不应有引号:

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

您可以使用动态更改按钮图标的这一选项

嵌入你的图标

[Embed(source='com/images/play.png')]
[Bindable]
public var imagePlay:Class; 

[Embed(source='com/images/pause.png')]
[Bindable]
public var imagePause:Class;
使用一个按钮切换视频的播放和暂停

private function playpause():void
{
    if (seesmicVideo.playing)
    {
        seesmicVideo.pause();
        btn_play.setStyle("icon",imagePlay);
    }
    else
    {
        seesmicVideo.play();
        btn_play.setStyle("icon",imagePause);
    }
}        

我可以使用按钮中的图标和以下代码:

<mx:Button id="buttonPlay" label="Play" click="playButtonClicked();" enabled="false" icon="@Embed('./play.png')"/>

play.png文件与mxml文件位于同一文件夹中

我使用的是Flash Builder版本4.6


编辑:问题是关于ActionScript,而不是MXML,但我留下这个答案仅供参考。

添加缺少的结束引号/paren没有任何区别。我仍然收到一个运行时错误,类型强制失败:无法将“@Embed(source='images/closeWindowUp.png')”转换为类。我调用buttonHBox.addChild(closeButton);这就是你所说的添加到stage的意思吗?对我来说,这只是给出了以下错误:
1041:属性不可调用。
。不过,我使用的是Flex3。