Eric Cancil原发布的FlowContainer组件链接好像大多都失效,我组件整理了一下,共大家学习使用
简介:FlowContainer组件,它可以实现子组件自动换行的功能。当某个子组件的大小动态改变的时候,它会根据自身的大小和子组件的总大小调整布局:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:container="com.appdivision.view.container.*">
<container:FlowContainer id="fc"
verticalGap="{hGSlider.value}" horizontalGap="{vGSlider.value}"
width="{wSlider.value}" height="{hSlider.value}"
/>
<mx:VBox
backgroundColor="white"
right="0" top="0"
>
<mx:FormItem
label="width">
<mx:HSlider id="wSlider"
liveDragging="true"
tickInterval="50"
value="500"
minimum="10" maximum="{this.width}"/>
</mx:FormItem>
<mx:FormItem
label="height">
<mx:HSlider id="hSlider"
liveDragging="true"
tickInterval="50"
value="500"
minimum="10" maximum="{this.height}"/>
</mx:FormItem>
<mx:FormItem
label="vertical gap">
<mx:HSlider id="hGSlider"
liveDragging="true"
tickInterval="1"
value="1"
minimum="1" maximum="100"/>
</mx:FormItem>
<mx:FormItem
label="horizontal gap">
<mx:HSlider id="vGSlider"
liveDragging="true"
tickInterval="1"
value="1"
minimum="1" maximum="100"/>
</mx:FormItem>
<mx:FormItem
label="Direction">
<mx:ComboBox id="directionCombo"
change="{fc.direction = directionCombo.selectedLabel}"
dataProvider="{[FlowContainerLayout.HORIZONTAL, FlowContainerLayout.VERTICAL]}"/>
</mx:FormItem>
</mx:VBox>
<mx:Script>
<![CDATA[
import mx.effects.Move;
import mx.effects.easing.Bounce;
import com.appdivision.view.container.FlowContainerLayout;
import mx.effects.Resize;
import mx.controls.Button;
override protected function childrenCreated():void{
super.childrenCreated();
for(var i :Number = 0; i < 50; i ++){
var b:Button = new Button();
b.width = 150;
b.height = 25;
b.label = 'Click to expand';
var r:Resize = new Resize(b);
r.easingFunction = Bounce.easeOut;
b.setStyle('resizeEffect', r);
b.addEventListener(MouseEvent.CLICK, onClick);
fc.addChild(b);
}
}
private function onClick(e:MouseEvent):void {
var b:Button = e.target as Button;
//target是事件的调用对象(event dispatcher)、事件发送者,
//currentTarget是事件的处理对象(event processor)、事件处理者
if(!b)return;
if(b.width > 150 || b.height > 25) {
b.width = 150;
b.height = 25;
b.label = 'Click to expand';
} else {
b.width = getRandom(b.width, 500);
b.height = getRandom(b.height, 500);
b.label = 'Click to contract';
}
}
public function getRandom(_min:Number, _max:Number):Number {
var tNumber:Number;
tNumber = Math.round(Math.random()*(_max-_min))+_min;
return tNumber;
}
]]>
</mx:Script>
</mx:Application>
此外还有一个更重要的flex包要导入项目:com.jar