Flex中如何通过ActionScript创建一个包含ControlBar容器的Panel的例子

By Minidxer | April 20, 2009

接下来的例子演示了Flex中如何通过ActionScript,创建一个包含ControlBar容器的Panel。

让我们先来看一下Demo可以右键View Source或点击这里察看源代码):


下面是完整代码(或点击这里察看):

Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  3.         layout="vertical"
  4.         verticalAlign="middle"
  5.         backgroundColor="white"
  6.         creationComplete="init();">
  7.  
  8.     <mx:Script>
  9.         <![CDATA[
  10.             import mx.controls.Button;
  11.             import mx.controls.Text;
  12.             import mx.containers.ControlBar;
  13.             import mx.containers.Panel;
  14.  
  15.             private var panel:Panel;
  16.             private var cBar:ControlBar;
  17.             private var txt:Text;
  18.             private var btn:Button;
  19.  
  20.             private function init():void {
  21.                 txt = new Text();
  22.                 txt.text = "The quick brown fox jumped over the lazy dog.";
  23.                 txt.percentWidth = 100;
  24.  
  25.                 btn = new Button();
  26.                 btn.label = "Button";
  27.  
  28.                 cBar = new ControlBar();
  29.                 cBar.addChild(btn);
  30.  
  31.                 panel = new Panel();
  32.                 panel.title = "Panel title";
  33.                 panel.status = "status";
  34.                 panel.width = 160;
  35.                 panel.height = 140;
  36.                 panel.addChild(txt);
  37.                 panel.addChild(cBar);
  38.                 addChild(panel);
  39.             }
  40.         ]]>
  41.     </mx:Script>
  42.  
  43. </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: ControlBar, Panel | 2 Comments » | Tags: ,

你可能还对下列文章感兴趣:

2 comments | Add One

  1. hqcone - 03/2/2010 at 3:30 pm

    你好,网址为:http://blog.minidx.com/2009/04/20/2377.html,的页面16行有点遗漏。

  2. Minidxer - 03/2/2010 at 3:41 pm

    @hqcone
    恩,分号没显示出来. 已经修正. 谢谢!

Leave a Comment

Name(*):

E-Mail(*) :

Website :

Comments :

Search Posts