Flex 4 ridimensionare in modo dinamico contenitore padre per contenere i bambini
-
20-09-2019 - |
Domanda
C'è un modo semplice per fare un contenitore padre (ad esempio Group) ridimensiona quando è bambini ridimensionare?
Di seguito è riportato un piccolo esempio app. Quando ho messo la 200x200 'cibo' nel 'stomaco' lo stomaco e si tratta di 100x100 contenente 'corpo' dovrebbe ridimensionare per contenere il cibo.
Tutte le idee?
(da questa sostanza http://gist.github.com/301292 )
<?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/halo"
minWidth="1024"
minHeight="768"
creationComplete="application1_creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected function application1_creationCompleteHandler(event:FlexEvent):void {
}
protected function eatFoodTrigger_clickHandler(event:MouseEvent):void {
var food:Border = new Border();
food.setStyle('backgroundColor', 0x15DCA9);
food.width = 200;
food.height = 200;
stomach.addElement(food);
}
]]>
</fx:Script>
<s:Group verticalCenter="0" horizontalCenter="0">
<s:layout>
<s:VerticalLayout horizontalAlign="center" />
</s:layout>
<s:Label fontSize="24" text="The 100x100 pink/brown body has a stomach inside it.
Press eat and the stomach gets 200x200 'food' added to it.
I want the body and the stomach to expand to fit the food." width="200">
</s:Label>
<s:Border id="body"
backgroundColor="0x333333"
minWidth="100"
minHeight="100"
borderColor="0xFF4466"
borderWeight="5">
<s:Group id="stomach">
</s:Group>
</s:Border>
<s:Button id="eatFoodTrigger" click="eatFoodTrigger_clickHandler(event)" label="eat" />
</s:Group>
</s:Application>
Soluzione
Ok quindi è stato un bug nel Flex 4 sdk, ed è stato risolto. Impressionante.
Da: http://forums.adobe.com/thread/575252
Il vostro esempio funziona per me in un recente costruire. Forse era un bug in un vecchio costruire. Provare uno dei nuovi notturno costruisce:
http://opensource.adobe.com/wiki/display/flexsdk/DownloadFlex4
-Ryan
Altri suggerimenti
Ovviamente, questo è un po 'troppo tardi, ma si potrebbe avere sovresposta l'addElementAt metodo e ha aggiunto alcune funzionalità per il ridimensionamento lì. Qui di seguito, si può vedere come addElementAdd () dovrebbe / potrebbe essere sovrascritto.
//This would be placed in a custom component that extends Group. Your stomach would be this component.
override public function addElementAt(element:IVisualElement, index:int):IVisualElement
{
super.addElementAt(element, index);
ChangeWatcher.watch(element, "width", function():void{ resizeHandler(element) });
ChangeWatcher.watch(element, "height", function():void{ resizeHandler(element) });
}
private function resizeHandler(el:IVisualElement):void
{
var element:DisplayObject = el as DisplayObject;
//Rest of the resizing code.
}
So che questo ha lavorato per FLEX3 e Canvas, quindi dovrebbe funzionare anche con Flex4 e del Gruppo.