How to fix overlapping VBox children in a canvas? - apache-flex

I have multiple HBoxes inside a VBox inside a canvas like so:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*">
<mx:Canvas width="600" height="500">
<mx:VBox height="100%" left="10" right="10">
<mx:HBox width="100%" >
<mx:VBox width="48%" height="100%" horizontalAlign="left">
<mx:Label text="Label" />
</mx:VBox>
<mx:VBox width="48%" height="100%" horizontalAlign="left">
<mx:Label text="Label" />
<mx:HBox width="100%">
<mx:VBox width="48%">
<mx:Label text="Label" />
<mx:ComboBox />
</mx:VBox>
</mx:HBox>
</mx:VBox>
</mx:HBox>
<mx:VBox>
<mx:HBox>
<mx:Label text="Label" />
<mx:Label text="Label" />
</mx:HBox>
</mx:VBox>
<mx:HBox>
<mx:Label text="Label" />
<mx:ComboBox/>
</mx:HBox>
<mx:HBox>
<mx:VBox horizontalScrollPolicy="off" verticalScrollPolicy="off"
includeInLayout="false" >
<mx:Label text="Label" />
</mx:VBox>
<mx:VBox>
<mx:HBox horizontalScrollPolicy="off" verticalScrollPolicy="off"
includeInLayout="false"
>
<mx:VBox >
<mx:Label text="Text" />
<mx:ComboBox />
</mx:VBox>
<mx:VBox>
<mx:Label text="Label" />
<mx:ComboBox />
</mx:VBox>
</mx:HBox>
<mx:HBox horizontalScrollPolicy="off" verticalScrollPolicy="off"
includeInLayout="false"
>
<mx:VBox>
<mx:Label text="Label:"/>
<mx:ComboBox />
</mx:VBox>
<mx:VBox>
<mx:Label text="Label: "/>
<mx:ComboBox />
</mx:VBox>
</mx:HBox>
</mx:VBox>
</mx:HBox>
<mx:HBox >
<mx:Label text="Label:" />
<mx:CheckBox />
</mx:HBox>
</mx:VBox>
</mx:Canvas>
</mx:Application>
The last child in the VBox is overlapping with other components. How do you prevent children of a VBox in a Canvas from overlapping? How do you debug this situation?
I have tried the following:
Removing percent based sizing
IncludeInLayout = true
Sceenshot - Label and Checkbox Overlapping:

It's hard to say with the information provided, but the two questions that come to mind first are:
Is your VBox height greater than the sum of the heights of its children?
Have you set the verticalGap property on the VBox? verticalGap determines vertical spacing between children.

I just tried this (AIR app) and it looks alright to me.
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Canvas height="100%" width="100%"
borderStyle="solid"
backgroundColor="0x0000ff">
<mx:VBox height="100%" width="100%">
<mx:VBox backgroundColor="0xff0000" height="50%" width="100%">
<mx:HBox backgroundColor="0x000000" height="50%" width="50%"/>
<mx:HBox backgroundColor="0xffffff" height="50%" width="50%"/>
<mx:HBox backgroundColor="0x00ffff" height="50%" width="50%"/>
</mx:VBox>
<mx:HBox height="50%" width="100%"
backgroundColor="0xff0000" backgroundAlpha="0.5"
borderColor="0x000000" borderStyle="solid" borderThickness="1"/>
</mx:VBox>
</mx:Canvas>
</mx:WindowedApplication>

I resolved this by making the includeInLayout property of some of these components the same conditional used by their visible property.
Not sure what caused the issue though.

Related

Actionscript- How do I set a click handler on a tab in TabNavigator?

I want the TextArea under my second tab to update when the tab is clicked. However, it's only updating when I click on the TextArea or the container for that text area.
Flex:
<mx:Box paddingLeft="0" paddingRight="0" paddingBottom="0" paddingTop="0" width="100%" height="100%"
<mx:VBox id="vbxHTMLBody" width="100%" height="100%" horizontalScrollPolicy="off" horizontalAlign="center">
<mx:TabNavigator id = "tabNav" borderStyle="solid" width="100%" height="100%" creationPolicy="all">
<mx:VBox label="Tab1" width="100%" height="100%">
<mx:TextArea id="textArea1" paddingTop="25" paddingLeft="25" paddingRight="25" verticalScrollPolicy="on" focusThickness="0" borderThickness="0" borderStyle="none" editable="true" fontFamily="Arial" fontSize="14" width="100%" height="100%"/>
</mx:VBox>
<mx:VBox label="Tab2" width="100%" height="100%" click="updateTextArea2()">
<mx:TextArea id="textArea2" paddingTop="25" paddingLeft="25" paddingRight="25" verticalScrollPolicy="on" focusThickness="0" borderThickness="0" borderStyle="none" editable="true" fontFamily="Arial" fontSize="14" width="100%" height="100%"/>
</mx:VBox>
</mx:TabNavigator>
</mx:VBox>
</mx:Box>
ActionScript:
private function updateTextArea2(): void {
textArea2.htmlText = textArea1.text;
tabNav.validateNow();
textArea2.validateNow();
}
*I've also tried setting the click listener to the outer containers and that hasn't worked either.
I used change="updateTextArea2()" to listen for any changes made to the text area.
Call updateTextArea2()on change of the TabNavigator:
<mx:TabNavigator id="tabNav" change=updateTextArea2()">
instead from VBox change.

How to create auto resizeable text item renderer in Flex MX list?

My Flex MX list has this itemRenderer
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" autoLayout="true" horizontalScrollPolicy="off">
<mx:Label y="0" right="0" text="{data.hour}" textAlign="right"/>
<mx:HBox left="0" right="0">
<mx:Label text="{data.username}" />
<mx:Text id="text1" text="{data.text}"/>
<mx:Image />
<mx:Button />
</mx:HBox>
</mx:Canvas>
My problem is : I want the MX Text id="text1" to be multi line if {data.text} grows.
Set width and height properties to mx:Text component

How to align the formItems?

I'm trying to create a form, but i am having issues aligning the formItems.
This is mx:Form namespace. (xmlns:mx="http://www.adobe.com/2006/mxml")
does anyone have any suggestions on how to correct this. any help would be greatly appreciated.
<mx:VBox paddingLeft="0" height="100%">
<form:Form width="100%"
textAlign="left">
<mx:VBox>
<mx:HBox id="snapShotSelect">
<form:FormItem label="My Label Here"
includeInLayout="{model.formItemVisible}"
visible="{model.formItemVisible}"/>
<mx:VBox>
<form:FormItem includeInLayout="{model.formItemVisible}"
visible="{model.formItemVisible}">
<components:SageTextInput textAlign="left"/>
</form:FormItem>
<form:FormItem label=""
visible="{model.formItemVisible}"
includeInLayout="{model.formItemVisible}"/>
<form:FormItem visible="{model.formItemVisible}"
includeInLayout="{model.formItemVisible}">
<components:SageList id="snaps"
allowMultipleSelection="false"
width="200"
rowCount="5"/>
</form:FormItem>
</mx:VBox>
</mx:HBox>
<mx:HBox>
<form:FormItem label="My Label Here"
width="100%"
visible="{model.formItemVisible}"
includeInLayout="{model.formItemVisible}"/>
<form:FormItem label=""
width="100%">
<components:SageComboBox dataProvider="{model.generations}"
textAlign="left"
enabled="{model.generations.length > 0}"/>
</form:FormItem>
</mx:HBox>
<mx:HBox id="radioSelectGroup">
<form:FormItem label="">
<components:SageRadioButtonGroup id="rbGroup"
groupId="rbGroup"
labelPlacement="right"/>
</form:FormItem>
</mx:HBox>
<mx:HBox id="radioNew">
<form:FormItem>
<components:SageRadioButton id="radioCopy" value="{model.RADIO_CREATE}"
group="{rbGroup}"
labelPlacement="right"
width="250"
label="Radio Button 1" />
</form:FormItem>
<form:FormItem>
<components:SageTextInput textAlign="left"
enabled="{rbGroup.selectedValue == model.RADIO_CREATE}"/>
</form:FormItem>
</mx:HBox>
<mx:HBox id="radioExisting">
<form:FormItem>
<components:SageRadioButton id="radioNoCopy" value="{model.RADIO_USE_EXISTING}"
group="{rbGroup}"
labelPlacement="right"
width="250"
label="Radio Button 2"/>
</form:FormItem>
<mx:VBox>
<form:FormItem label=""
paddingBottom="0">
<components:SageTextInput textAlign="left"
enabled="{rbGroup.selectedValue == model.RADIO_USE_EXISTING}"/>
</form:FormItem>
<form:FormItem label=""
indentationLevel="0"
paddingTop="0">
<components:SageList allowMultipleSelection="false"
width="200"
rowCount="5"
enabled="{rbGroup.selectedValue == model.RADIO_USE_EXISTING}"/>
</form:FormItem>
</mx:VBox>
</mx:HBox>
</mx:VBox>
</form:Form>
</mx:VBox>
It Looks like this at the moment.
But i want it to look like this
Use the following code : Please adjust the width of spacer according to your alignment requirements. Also Dont miss out mentioning the width of every HBox and VBox inside the formItem. Here, I am using all mx components.
<mx:Form>
<mx:FormItem width="100%">
<mx:VBox id="ContainerVBox" width="100%">
<mx:HBox width="100%">
<mx:Label id="label1" text="my label here"/>
<mx:Spacer width="10%"/>
<mx:TextInput id="textInput1" text="This is text input 1"/>
</mx:HBox>
<mx:TextInput id="textInput2" text="This is text input 2"/>
</mx:VBox>
</mx:FormItem>
<mx:FormItem width="100%">
<mx:HBox width="100%">
<mx:Label id="label1" text="my label here"/>
<mx:Spacer width="10%"/>
<mx:ComboBox id="myComboBox"/>
</mx:HBox>
</mx:FormItem>
<mx:FormItem width="100%">
<mx:HBox width="100%">
<mx:RadioButton id="myRadioButton"/>
<mx:Text text="Radio Button 1"/>
<mx:Spacer width="10%"/>
<mx:TextInput id="textInput3"/>
</mx:HBox>
</mx:FormItem>
<mx:FormItem width="100%">
<mx:VBox width="100%">
<mx:HBox width="100%">
<mx:RadioButton id="myRadioButton"/>
<mx:Text text="Radio Button 2"/>
<mx:Spacer width="10%"/>
<mx:TextInput id="textInput4"/>
</mx:HBox>
<mx:TextInput id="textInput5" text="This is text input 5"/>
</mx:VBox>
</mx:FormItem>
</mx:Form>
</mx:VBox>

Flex VBox border

How do I add a border to a Flex VBox? My VBox is the renderer of a List. I've tried the following without success (in particular VBox's borderVisible="true" borderStyle="solid" borderColor="0x888888"):
<mx:List id="myList" dataProvider="{myData}"
width="100%" height="100%"
variableRowHeight="true"
verticalScrollPolicy="auto" horizontalScrollPolicy="auto">
<mx:itemRenderer>
<mx:Component>
<mx:VBox
width="100%" height="100%"
verticalScrollPolicy="off" horizontalScrollPolicy="off"
borderVisible="true" borderStyle="solid" borderColor="0x888888">
<mx:HBox width="100%">
<mx:Label id="firstNameLabel" text="{data.firstName}"/>
<mx:Label id="lastNameLabel" text="{data.lastName}"/>
</mx:HBox>
<mx:Text id="descriptionLabel" text="{data.description}"/>
</mx:VBox>
</mx:Component>
</mx:itemRenderer>
</mx:List>
There is no borderVisible style or property on the Flex Container classes.
To see a border you need to set the borderStyle, borderColor and borderThickness styles.
Try the following styles for your VBox:
<mx:VBox
borderThickness="1" borderStyle="solid" borderColor="0x888888" ...>
...
</mx:VBox>
And in actionscript 3:
private var _vbox:VBox;
...
this._vbox.setStyle("borderThickness", "1");
this._vbox.setStyle("borderStyle", "solid");
this._vbox.setStyle("borderColor", "0x888888");
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
private var myData:ArrayCollection = new ArrayCollection([
{label:'a11',url: '../dol/assets/images/lalign.png', side:'left'},
{label:'a323',url: '../dol/assets/images/calign.png', side:'center'},
{label:'asdf45',url: '../dol/assets/images/ralign.png', side:'right'}]);
]]>
</mx:Script>
<mx:List id="myList" dataProvider="{myData}"
width="100%" height="100%"
variableRowHeight="true"
verticalScrollPolicy="auto" horizontalScrollPolicy="auto">
<mx:itemRenderer>
<mx:Component>
<mx:VBox width="100%" height="100%"
verticalScrollPolicy="off" horizontalScrollPolicy="off"
borderStyle="solid" borderColor="0x888888" borderThickness="3">
<mx:HBox width="100%">
<mx:Label id="firstNameLabel" text="{data.label}"/>
<mx:Label id="lastNameLabel" text="{data.url}"/>
</mx:HBox>
<mx:Text id="descriptionLabel" text="{data.side}"/>
</mx:VBox>
</mx:Component>
</mx:itemRenderer>
</mx:List>
</mx:Application>
borderVisible is nothing in flex, use borderStyle=solid, borderThickness, and borderColor attributes to show border

flex: how to Make two resize effect at the same time

Hy,
Is it possible to resize the application at the same moment when the Accordion size change, to make effect resize og the last one synchronised with resize of Application ?
In my code,, the Application is resized after the resize of Accordion is completed:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" minWidth="400" minHeight="300" backgroundColor="white" horizontalScrollPolicy="off" verticalScrollPolicy="off" mouseDown="stage.nativeWindow.startMove()">
<mx:Resize id="expand" target="{application}" heightTo="{acc01.height}"/>
<mx:Accordion id="acc01" x="0" y="0" resizeToContent="true" resize="expand.play();" horizontalScrollPolicy="off" verticalScrollPolicy="off">
<mx:VBox label="Accordion Pane 1" width="100%" height="100%">
<mx:Label text="hello"/>
<mx:Label text="hello"/>
<mx:Label text="hello"/>
<mx:Label text="hello"/>
</mx:VBox>
<mx:VBox label="Panel 2" width="100%" height="100%">
<mx:Label text="hello"/>
<mx:Label text="hello"/>
</mx:VBox>
<mx:VBox label="Panel 3" width="100%" height="100%">
<mx:Label text="hello"/>
<mx:Label text="hello"/>
</mx:VBox>
<mx:VBox label="Panel 4" width="100%" height="100%">
<mx:Label text="hello"/>
<mx:Label text="hello"/>
</mx:VBox>
</mx:Accordion>
</mx:Application>
Have a look at http://livedocs.adobe.com/flex/3/langref/mx/effects/Parallel.html, it might do what you need.

Resources