现在的位置: 首页 > 综合 > 正文

在flex中使用CSS改变控件样式

2013年08月27日 ⁄ 综合 ⁄ 共 1007字 ⁄ 字号 评论关闭

昨天在搞一个对话框的外观 使用CSS搞定

http://www.riashanghai.com/node/7这篇文章对我帮助很大

 

心得写一下,自己留着好看

 

需要一个CSS文件,例如Default.CSS
在mxml中需要使用
<mx:Style source="Default.css"></mx:Style>
进行捆绑

对控件进行绑定
例如:控件 MyButton
需要在Default.css文件中输入和控件类名相同的项
方法一
MyButton
{
  /*MC*/
  upSkin:Embed(source="button.swf", symbol="up_skin");
  /*PNG, BMP好像不行*/
  downSkin:Embed("down_skin.png",
      scaleGridLeft="10",
      scaleGridRight="300",
      scaleGridTop="20",
      scaleGridBottom="400");
  /*自定义项*/
  test:"this is test string!"
}
这样就直接绑定了!
var btn:MyButton = new Mybutton();
var str:String = btn.getStyle("test");
str值就等于"this is test string!"

方法二
/*名字可以随命名*/
.MyButtonSecond
{
  /*MC*/
  upSkin:Embed(source="button.swf", symbol="up_skin");
  /*PNG, BMP好像不行*/
  downSkin:Embed("down_skin.png",
      scaleGridLeft="10",
      scaleGridRight="300",
      scaleGridTop="20",
      scaleGridBottom="400");
   /*自定义项*/
  test:"this is test string!"
}

flex:
<mx:MyButton xmlns:mx="http://www.adobe.com/2006/mxml" width="370" height="222" styleName="MyButtonSecond">
或者
btn.styleName = MyButtonSecond;
这样就绑定了!

比如背景色 背景图片之类的项 查文档就可以知道了或者google

【上篇】
【下篇】

抱歉!评论已关闭.