Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3351804
  • 博文数量: 530
  • 博客积分: 13360
  • 博客等级: 上将
  • 技术积分: 5473
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-13 13:32
文章分类

全部博文(530)

文章存档

2017年(1)

2015年(2)

2013年(24)

2012年(20)

2011年(97)

2010年(240)

2009年(117)

2008年(12)

2007年(8)

2006年(9)

分类: 系统运维

2011-06-30 21:55:26

1.概述
下拉窗体技术在很多地方都要运用到,效果如
     
现在有三种实现技术,下面分别简述

2.通过flexlib开源项目的WindowShade实现
      演示地点:
      优点:功能强大,复用性好,有发展钱途
      缺点:在FLEX4下无法实现open/close时变换图标
      本人虽然通过变通的方法实现,但是不是最理想解决方案

3.通过展示Panel实现
       优点:直接继承panel,实现简单,通过改变panel的长度实现open/close
       缺点:界面死板,header无法设置图标,必须通过点击button才能实现open/close

源代码如下
  1. package flexlib
  2. {
  3.     import flash.events.MouseEvent;
  4.     import mx.containers.Canvas;
  5.     import mx.containers.Panel;
  6.     import mx.controls.Button;
  7.     import mx.controls.Image;
  8.     import mx.core.*;
  9.     import mx.effects.Resize;
  10.     import mx.effects.easing.Bounce;
  11.     import mx.styles.*;
  12.     
  13.     public class define_panel extends Panel
  14.     {
  15.         public var btn:Button;
  16.         public var can:Canvas;
  17.         public var resize:Resize=new Resize();
  18.         
  19.         [Embed(source="/assets/bullet_green.png")]
  20.         private var backgroup_img:Class;
  21.         
  22.         [Embed(source="/assets/bullet_red.png")]
  23.         private var ion:Class;
  24.         private var iimg:Image=new Image();
  25.         //private var img:Image=Image(backgroup_img);
  26.         public function define_panel()
  27.         {
  28.             super();
  29.             resize.heightTo=this.height;
  30.             resize.easingFunction=Bounce.easeOut;
  31.         }
  32.         /**
  33.          * override updateDisplayList method
  34.          */
  35.         override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
  36.             super.updateDisplayList(unscaledWidth, unscaledHeight);
  37.             titleBar.visible = true;
  38.             
  39.         }
  40.         
  41.         override protected function createChildren():void
  42.         {
  43.             iimg.source="http://blog.minidx.com/ext02/image2.jpg";
  44.             super.createChildren();
  45.             can=new Canvas();
  46.             can.width=this.width;
  47.             can.height=36;
  48.             can.toolTip="canvas";
  49.             can.setStyle("backgroundColor","blue");
  50.             can.setStyle("backgroundAlpha","0.31");
  51.             // can.setStyle("backgroundImage","resources/img/defpanel_backimg.jpg");
  52.             
  53.             btn=new Button();
  54.             btn.label="down";
  55.             btn.width=18;
  56.             btn.height=12;
  57.             btn.addEventListener(MouseEvent.CLICK,resize_panel);
  58.             can.addChild(btn);
  59.             this.addChild(iimg);
  60.             super.titleIcon=ion;
  61.             this.rawChildren.addChild(can);
  62.             
  63.         }
  64.         
  65.         protected override function layoutChrome(unscaledWidth: Number, unscaledHeight:Number):void {
  66.             //trace("++1");
  67.             super.layoutChrome(unscaledWidth,unscaledHeight);
  68.             
  69.             btn.move(can.width-35,10);
  70.             // btn1.move(can.width-btn.width-45,10);
  71.             can.move(0,0);
  72.         }
  73.         
  74.         private function resize_panel(evt:MouseEvent):void{
  75.             
  76.             resize.heightTo=resize.heightTo==this.titleBar.height?400:this.titleBar.height;
  77.             // trace(( resize.heightTo=resize.heightTo==this.titleBar.height?300:this.titleBar.height));
  78.             resize.duration=1000;
  79.             resize.easingFunction = resize.easingFunction==Bounce.easeOut?Bounce.easeIn:Bounce.easeOut;
  80.             resize.target=this;
  81.             resize.play();
  82.         }
  83.     }
  84. }
运行代码如下
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:Application xmlns:fx=""
  3.              xmlns:s="library://ns.adobe.com/flex/spark"
  4.              xmlns:mx="library://ns.adobe.com/flex/mx"
  5.              xmlns:ns="flexlib.*"
  6.              minWidth="955" minHeight="600">
  7.     <ns:define_panel width="800" height="600"/>
  8. </s:Application>

4.通过开源扩展Panel实现
       演示地址:
       优点:直接继承panel,实现简单,通过改变panel的长度实现open/close
       缺点:好象无法在FLEX4下修改源代码,好象无法设置图标,通过双击实现实现open/close
运行代码
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:Application xmlns:fx=""
  3.              xmlns:s="library://ns.adobe.com/flex/spark"
  4.              xmlns:mx="library://ns.adobe.com/flex/mx"
  5.              xmlns:containers="com.arc90.flexlib.containers.*"
  6.              minWidth="955" minHeight="600">
  7.     <containers:CollapsiblePanel title="Collapsible Panel" status="This is status text." collapseDuration="200" width="400"
  8.                                  height="400"/>
  9. </s:Application>

5.通过状态切换实现
       优点:不知
       缺点:代码大,暂无法运行
代码如下
SkinShade.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:SkinnableContainer xmlns:fx=" "
  3.                      xmlns:s="library://ns.adobe.com/flex/spark"
  4.                      xmlns:mx="library://ns.adobe.com/flex/mx"
  5.                      width="96%" height="70"
  6.                      skinClass="flexlib.MySin">
  7.     <s:layout>
  8.         <s:VerticalLayout/>
  9.     </s:layout>
  10.     
  11.     
  12.     <fx:Script>
  13.         <![CDATA[
  14.         import com.greensock.TweenMax;
  15.         import com.zctt.alltouch.system.common.event.SysteMenuEvent;
  16.         
  17.         private var data:Object;
  18.         
  19.         protected function btnClick(event:MouseEvent):void{
  20.         var btn:Button = event.currentTarget as Button;
  21.         if(btn.styleName == 'downBtn'){
  22.         btn.styleName = 'upBtn';
  23.         TweenMax.to(this,0.6,{height:200});
  24.         info.verticalScrollPolicy = 'auto';
  25.         info.horizontalScrollPolicy = 'auto';
  26.         }else{
  27.         btn.styleName = 'downBtn';
  28.         info.verticalScrollPolicy = 'off';
  29.         info.horizontalScrollPolicy = 'off';
  30.         TweenMax.to(this,0.6,{height:70});
  31.         }
  32.         }
  33.         
  34.         public function init(obj:Object):void{
  35.         this.data = obj;
  36.         info.text = obj.description;
  37.         title.text = obj.name;
  38.         }
  39.         
  40.         protected function change(event:MouseEvent):void
  41.         {
  42.         this.dispatchEvent(new SysteMenuEvent(SysteMenuEvent.CHANGE,data));
  43.         }
  44.         
  45.         ]]>
  46.     </fx:Script>
  47.     <s:Group width="100%" height="35">
  48.         <mx:Image source="assets/bullet_green.png" left="10" bottom="8"/>
  49.         <mx:Label id="title" left="30" bottom="6" height="23"/>
  50.         
  51.         <mx:Label htmlText="进入" right="70" bottom="8" click="change(event)"/>
  52.         <mx:Button styleName="downBtn" right="30" bottom="8" buttonMode="true" click="btnClick(event)"/>
  53.         <mx:HRule width="98%" height="6" bottom="-2" horizontalCenter="0"/>
  54.     </s:Group>
  55.     <s:Group width="100%" height="100%">
  56.         <mx:TextArea height="100%" id="info" selectable="false" focusEnabled="false" focusAlpha="0" borderVisible="false" width="100%" horizontalScrollPolicy="off" verticalScrollPolicy="off" borderStyle="none" left="60" right="60"/>
  57.     </s:Group>
  58. </s:SkinnableContainer>

mysin.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:Skin xmlns:fx=" " xmlns:s="library://ns.adobe.com/flex/spark"
  3.         xmlns:fb=" " alpha.disabled="0.5">
  4.     
  5.     <fx:Metadata>
  6.         <![CDATA[
  7.         /**
  8.         * @copy spark.skins.spark.ApplicationSkin#hostComponent
  9.         */
  10.         [HostComponent("spark.components.SkinnableContainer")]
  11.         ]]>
  12.     </fx:Metadata>
  13.     
  14.     <s:states>
  15.         <s:State name="normal" />
  16.         <s:State name="disabled" />
  17.     </s:states>
  18.     
  19.     <!--- Defines the appearance of the SkinnableContainer class's background. -->
  20.     
  21.         
  22.             
  23.             
  24.                 
  25.                     
  26.                     
  27.                 
  28.             
  29.         
  30.     
  31.     
  32.     
    阅读(3557) | 评论(0) | 转发(0) |
    0

    上一篇:mx.core.IDataRenderer

    下一篇:FLEX4_显示滚动条

给主人留下些什么吧!~~