BorderContainer 动态的添加子元素

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 

  xmlns:s="library://ns.adobe.com/flex/spark" 

  xmlns:mx="library://ns.adobe.com/flex/mx" 

  applicationComplete="callLater(init)"

  width="500" height="375">

<s:layout>

<s:BasicLayout/>

</s:layout>

<fx:Style source="assets/snow.css"/>

<fx:Declarations>

<!-- 将非可视元素(例如服务、值对象)放在此处 -->

</fx:Declarations>

<fx:Script>

<![CDATA[

import mx.core.UIComponent;

 

import tea.SnowFlake;

 

private var snowArr:Array;

private var snowNum:Number;

 

private function init():void{

snowArr = new Array();

//创建雪花

 

 

var snow:SnowFlake = new SnowFlake();

snow.x = 50;

snow.y = 50;

var ui:UIComponent = new UIComponent();

ui.addChild(snow);

bc.addElement(ui);

}

]]>

</fx:Script>

<s:BorderContainer id="bc" x="0" y="0" width="500" height="375" >

</s:BorderContainer>

</s:Application>

 

snowFlake类

package tea{

import flash.display.Sprite;

 

public class SnowFlake extends Sprite{

 

private var radius:Number;

private var color:Number;

 

public function SnowFlake(radius:Number=5, color:Number=0xFFFFFF)

{

this.radius = radius;

this.color = color;

drawSnow();

}

public function drawSnow():void{

graphics.beginFill(this.color, 1);

graphics.drawCircle(0,0,this.radius);

graphics.endFill();

}

}

}

posted on 2012-02-25 08:07  唐朝  阅读(350)  评论(0编辑  收藏  举报