我想使用Actionscript动态地在Flex中创建带有图标的按钮。在动作中创建一个带有图标的按钮
我试过了,没有成功:
var closeButton = new Button();
closeButton.setStyle("icon", "@Embed(source='images/closeWindowUp.png");
我想使用Actionscript动态地在Flex中创建带有图标的按钮。在动作中创建一个带有图标的按钮
我试过了,没有成功:
var closeButton = new Button();
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缺少一个关闭引号/ paren。
closeButton.setStyle("icon", "@Embed(source='images/closeWindowUp.png");
应该是:
closeButton.setStyle("icon", "@Embed(source='images/closeWindowUp.png')");
的错误是在报价,应该有@Embed
周围没有引号:
closeButton.setStyle("icon", @Embed(source="images/closeWindowUp.png"));
对我来说,这只是给出了以下错误:`1041:属性不可调用.`。不过,我正在使用Flex 3。 – edam 2014-07-02 14:00:41
您可以使用按钮图标的动态变化的这一个选项。
嵌入你的图标
[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')”转换为Class。我打电话给 buttonHBox.addChild(closeButton); 这是你加入舞台的意思吗? – 2008-11-18 23:58:49