积少成多Flash(9) - Flex 3.0 布局控件, 样式(css), 皮肤(skin)

2024-03-23 14:08

本文主要是介绍积少成多Flash(9) - Flex 3.0 布局控件, 样式(css), 皮肤(skin),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

[索引页]
[源码下载]

积少成多Flash(9) - Flex 3.0 布局控件, 样式(css), 皮肤(skin)



作者:webabcd


介绍
演示 Flex 3.0 中的布局控件的应用,样式和皮肤的应用 

  • 布局控件 - Flex 中常用的布局控件一览
  • 样式 - 通过 css 控制 Flex 中各个控件的样式
  • 皮肤 - 使用 Flash 开发的 swf 做控件的皮肤



在线DEMO
http://www.cnblogs.com/webabcd/archive/2009/11/09/1598980.html


1、布局控件一览
Layout.mxml

<? xml version="1.0" encoding="utf-8" ?>
< mx:Panel  xmlns:mx ="http://www.adobe.com/2006/mxml"  layout ="absolute"  
    title
="Layout 常用布局控件一览"  width ="476"  height ="427" >
    
    
< mx:Script >
        
<![CDATA[
        
            import mx.controls.Alert;
            
            private function submitForm(e:MouseEvent):void
            {
                Alert.show("Item1: " + item1.text, "Alert框");
            }
            
        
]]>
    
</ mx:Script >
    
    
<!--
        HBox - 水平线性布局
        VBox - 垂直线性布局
    
-->
    
< mx:HBox  x ="10"  y ="10"  width ="438"  horizontalGap ="50"  borderThickness ="1"  borderStyle ="solid" >
        
< mx:Label  text ="HBox - Label1" />
        
< mx:Label  text ="HBox - Label2" />
    
</ mx:HBox >
    
    
<!--
        HDividedBox - 在 HBox 的基础上,以垂直方向显示分隔条
        VDividedBox - 在 VBox 的基础上,以水平方向显示分隔条
    
-->
    
< mx:HDividedBox  x ="10"  y ="36"  width ="438"  borderThickness ="1"  borderStyle ="solid" >
        
< mx:Label  text ="HDividedBox - Label1" />
        
< mx:Label  text ="HDividedBox - Label2" />
    
</ mx:HDividedBox >
    
    
<!--
        Panel - 面板。可设置其标题,内容等
    
-->
    
< mx:Panel  width ="171"  height ="97"  layout ="absolute"  title ="Panel - Title"  x ="10"  y ="64"  borderThickness ="1"  borderStyle ="solid" >
        
< mx:Label  text ="Panel - Label1" />
    
</ mx:Panel >
    
    
<!--
        Grid - 网格型布局控件
    
-->
    
< mx:Grid  x ="10"  y ="169"  borderThickness ="1"  borderStyle ="solid" >
        
< mx:GridRow  width ="100%"  height ="100%" >
            
< mx:GridItem  width ="100%"  height ="100%" >
                
< mx:Label  text ="Grid - Label1" />
            
</ mx:GridItem >
            
< mx:GridItem  width ="100%"  height ="100%" >
                
< mx:Label  text ="Grid - Label2" />
            
</ mx:GridItem >
        
</ mx:GridRow >
        
< mx:GridRow  width ="100%"  height ="100%" >
            
< mx:GridItem  width ="100%"  height ="100%"  colSpan ="2"  horizontalAlign ="center" >
                
< mx:Label  text ="Grid - Label3" />
            
</ mx:GridItem >
        
</ mx:GridRow >
    
</ mx:Grid >
    
    
<!--
        Form - 用于构建表单型布局
    
-->
    
< mx:Form  x ="189"  y ="64"  width ="259"  height ="149"  borderThickness ="1"  borderStyle ="solid" >
        
< mx:FormHeading  label ="Form - Head" />
        
< mx:FormItem  label ="Item1: " >
            
< mx:TextInput  id ="item1"   />     
        
</ mx:FormItem >
        
< mx:FormItem >
            
< mx:HRule  height ="1"  width ="100%"   />
            
< mx:Button  label ="Form - Submit"  click ="submitForm(event)"   />
        
</ mx:FormItem >
    
</ mx:Form >
    
    
<!--
        Canvas - 绝对定位布局控件
    
-->
    
< mx:Canvas  width ="438"  height ="84"  x ="10"  y ="221"  borderThickness ="1"  borderStyle ="solid" >
        
< mx:Label  text ="Canvas - Label1" />
        
< mx:Label  text ="Canvas - Label2"  x ="104"  y ="10" />
        
< mx:Label  text ="Canvas - Label3"  x ="208"  y ="20" />
    
</ mx:Canvas >
    
    
<!--
        ApplicationControlBar - 显示为一个条形控件
    
-->
    
< mx:ApplicationControlBar  x ="10"  y ="313"  width ="436" >
        
< mx:Label  text ="ApplicationControlBar - Label1" />
    
</ mx:ApplicationControlBar >
        
    
<!--
        ControlBar - Panel 底部的条形控件
        Spacer - 不用于显示,纯粹占位用
    
-->
    
< mx:ControlBar >
        
< mx:Label  text ="Panel - ControlBar - Label1" />
        
< mx:Spacer  width ="100%"  x ="154"  y ="350" />
        
< mx:Label  text ="Panel - ControlBar - Label2" />
    
</ mx:ControlBar >
</ mx:Panel >



2、样式的控制
样式

/* 
 * Flex 也支持 CSS 中的类型选择符
 * 此种类型选择符必须设置在外部,然后由具体的 mxml 引用,直接将其写在 <mx:Style /> 中无效
 
*/

Application
{
    font-size
: 12px;
}

引用样式

< mx:Style  source ="style.css"   />


css.mxml(Flex 中样式相关的演示)

<? xml version="1.0" encoding="utf-8" ?>
< mx:Panel  xmlns:mx ="http://www.adobe.com/2006/mxml"  layout ="absolute"  width ="400"  height ="300"
    initialize
="init();"
    title
="CSS 的应用" >
    
    
< mx:Script >
        
<![CDATA[
    
            // 重写已声明的样式
            // 其中样式 “italic” 已在 <mx:Style /> 中做了声明
            private function init():void
            {
                var css:CSSStyleDeclaration = StyleManager.getStyleDeclaration(".italic");
                css.setStyle("fontStyle", "italic");
            }
            
            // 以编程方式指定样式
            private function setTextInputStyle():void
            {
                txt.setStyle("color", "Red");
            }
            
        
]]>
    
</ mx:Script >
    
    
< mx:Style >
        /* 在 Flex 中的做样式设置,基本与 CSS 相同 */
        
        .red 
        { 
            color: red;
        }
        .bold
        {
            font-weight: bold;
        }
        .italic
        {
            
        }
        
        .myClass
        {
            /* 使用内嵌图片做背景 */
            background-image:Embed("images/logo.png");
        }
    
</ mx:Style >        
    
    
<!-- 以声明方式指定样式(可以一次指定多个样式) -->
    
< mx:Label  text ="Label"  x ="10"  y ="10"  styleName ="red bold italic"   />
    
    
<!-- 以编程方式指定样式 -->
      
< mx:TextInput  id ="txt"  text ="TextInput"  x ="10"  y ="36"  initialize ="setTextInputStyle();"   />

    
< mx:VBox  styleName ="myClass"  x ="10"  y ="85" >
        
< mx:Label  text ="Label"  color ="yellow"  fontSize ="30"   />
    
</ mx:VBox >    
  
</ mx:Panel >



3、皮肤的使用
customButton.css

Button.customButton
{
    
/*
     * 如果要在运行时加载 skin 需要将其编译为 swf(在 .css 文件中单击右键,选择 Compile CSS to SWF)
     * 自定义皮肤:在 Flash 中要选择为 ActionScript 导出,在 Flash 中编辑皮肤时,要启用9切片(放大/缩小时边缘不会变形,也就是说边缘不随放大/缩小而变化)
     * 此处指定的 style/skin.swf 为在 Flash 中编辑的皮肤
     
*/

    upSkin
: Embed(source="style/skin.swf", symbol="Button_upSkin");
}


Skin.mxml

<? xml version="1.0" encoding="utf-8" ?>
< mx:Panel  xmlns:mx ="http://www.adobe.com/2006/mxml"  layout ="absolute"  width ="400"  height ="300"
    title
="Skin 的应用" >
    
    
< mx:Script >  
        
<![CDATA[
        
            // 应用自定义皮肤
            private function changeSkin():void
            {
                StyleManager.loadStyleDeclarations("style/customButton.swf");
                
                btn.styleName = "customButton"
            }
            
        
]]>
    
</ mx:Script >
    
    
< mx:Style  source ="style/customButton.css"   />
    
    
< mx:Button  id ="btn"  label ="换皮"  click ="changeSkin();"   />
    
</ mx:Panel >



4、ToolTip 的样式的控制
style.css

ToolTip 
{
    fontSize
: 12;
    fontStyle
: "italic";
    color
: #000000;
    backgroundColor
: #FCEA1E;
}


ToolTipDemo.mxml

<? xml version="1.0" encoding="utf-8" ?>
< mx:Panel  xmlns:mx ="http://www.adobe.com/2006/mxml"  layout ="absolute"  width ="400"  height ="300"
    title
="ToolTip 的 Demo" >
           
    
< mx:Style  source ="style.css"   />
     
    
< mx:TextInput  toolTip ="我是 TookTip"  x ="10"  y ="10" />
    
</ mx:Panel >



OK
[源码下载]

这篇关于积少成多Flash(9) - Flex 3.0 布局控件, 样式(css), 皮肤(skin)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/838536

相关文章

CSS place-items: center解析与用法详解

《CSSplace-items:center解析与用法详解》place-items:center;是一个强大的CSS简写属性,用于同时控制网格(Grid)和弹性盒(Flexbox)... place-items: center; 是一个强大的 css 简写属性,用于同时控制 网格(Grid) 和 弹性盒(F

CSS实现元素撑满剩余空间的五种方法

《CSS实现元素撑满剩余空间的五种方法》在日常开发中,我们经常需要让某个元素占据容器的剩余空间,本文将介绍5种不同的方法来实现这个需求,并分析各种方法的优缺点,感兴趣的朋友一起看看吧... css实现元素撑满剩余空间的5种方法 在日常开发中,我们经常需要让某个元素占据容器的剩余空间。这是一个常见的布局需求

CSS Anchor Positioning重新定义锚点定位的时代来临(最新推荐)

《CSSAnchorPositioning重新定义锚点定位的时代来临(最新推荐)》CSSAnchorPositioning是一项仍在草案中的新特性,由Chrome125开始提供原生支持需... 目录 css Anchor Positioning:重新定义「锚定定位」的时代来了! 什么是 Anchor Pos

CSS中的Static、Relative、Absolute、Fixed、Sticky的应用与详细对比

《CSS中的Static、Relative、Absolute、Fixed、Sticky的应用与详细对比》CSS中的position属性用于控制元素的定位方式,不同的定位方式会影响元素在页面中的布... css 中的 position 属性用于控制元素的定位方式,不同的定位方式会影响元素在页面中的布局和层叠关

HTML5 getUserMedia API网页录音实现指南示例小结

《HTML5getUserMediaAPI网页录音实现指南示例小结》本教程将指导你如何利用这一API,结合WebAudioAPI,实现网页录音功能,从获取音频流到处理和保存录音,整个过程将逐步... 目录1. html5 getUserMedia API简介1.1 API概念与历史1.2 功能与优势1.3

全面解析HTML5中Checkbox标签

《全面解析HTML5中Checkbox标签》Checkbox是HTML5中非常重要的表单元素之一,通过合理使用其属性和样式自定义方法,可以为用户提供丰富多样的交互体验,这篇文章给大家介绍HTML5中C... 在html5中,Checkbox(复选框)是一种常用的表单元素,允许用户在一组选项中选择多个项目。本

HTML5 搜索框Search Box详解

《HTML5搜索框SearchBox详解》HTML5的搜索框是一个强大的工具,能够有效提升用户体验,通过结合自动补全功能和适当的样式,可以创建出既美观又实用的搜索界面,这篇文章给大家介绍HTML5... html5 搜索框(Search Box)详解搜索框是一个用于输入查询内容的控件,通常用于网站或应用程

CSS3中的字体及相关属性详解

《CSS3中的字体及相关属性详解》:本文主要介绍了CSS3中的字体及相关属性,详细内容请阅读本文,希望能对你有所帮助... 字体网页字体的三个来源:用户机器上安装的字体,放心使用。保存在第三方网站上的字体,例如Typekit和Google,可以link标签链接到你的页面上。保存在你自己Web服务器上的字

html 滚动条滚动过快会留下边框线的解决方案

《html滚动条滚动过快会留下边框线的解决方案》:本文主要介绍了html滚动条滚动过快会留下边框线的解决方案,解决方法很简单,详细内容请阅读本文,希望能对你有所帮助... 滚动条滚动过快时,会留下边框线但其实大部分时候是这样的,没有多出边框线的滚动条滚动过快时留下边框线的问题通常与滚动条样式和滚动行

Python实现自动化Word文档样式复制与内容生成

《Python实现自动化Word文档样式复制与内容生成》在办公自动化领域,高效处理Word文档的样式和内容复制是一个常见需求,本文将展示如何利用Python的python-docx库实现... 目录一、为什么需要自动化 Word 文档处理二、核心功能实现:样式与表格的深度复制1. 表格复制(含样式与内容)2