Spark container not hiding contents outside of its body - actionscript-3

This is what what my screen looks like:
It is composed like this :
First container <s:HGroup>(900 X 100)--top black area
Second container <s:Group> (900 X 475)--middle white area
Third container <s:HGroup>--(900 X 100)--bottom black area
If the project were done with Flex 3, the middle area would be an <mx:Canvas>.
Now suppose I have one BorderContainer(125 X 475) and name it middleContainerChild. It is located on the right side of the middle area. When I set its y postion to -middleContainerChild.height, it should be located at y = -475, outside of the container's body. And as you can see in the image above, it has been placed there.
But other than with <mx:Canvas>, the image still shows, even though it is no longer within the <s:Group>s body, and it is rendered "on top" of the <s:HGroup>.
See the image below for more clarification:
If I use <mx:Canvas>, it is hidden away properly, but if I use a Spark container (not only a group, but any Spark container), it remains visible.
Has anyone else had this problem?

Read a bit about clipAndEnableScrolling property of GroupBase class.
Regards.

As 2DH gave me the hint, i have prepared this sample,
<?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" minWidth="900" minHeight="672">
<fx:Declarations>
<s:Move
id="moveUp"
yFrom="0"
yTo="-475"
target="{helpWindow}"/>
<s:Move
id="moveDown"
yFrom="-475"
yTo="0"
target="{helpWindow}"/>
</fx:Declarations>
<fx:Script>
<![CDATA[
private function buttonUp_clickHandler(event:MouseEvent):void
{
moveUp.play();
}
private function buttonDown_clickHandler(event:MouseEvent):void
{
moveDown.play();
}
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout gap="0"/>
</s:layout>
<s:BorderContainer
backgroundColor="#000000"
height="100"
width="100%"/>
<s:Group
height="475"
width="100%"
clipAndEnableScrolling="true">
<s:VGroup
left="0"
top="0">
<s:Button
label="Play Effect UP"
click="buttonUp_clickHandler(event)"/>
<s:Button
label="Play Effect DOWN"
click="buttonDown_clickHandler(event)"/>
</s:VGroup>
<s:BorderContainer
id="helpWindow"
backgroundColor="#CCCCCC"
y="{-helpWindow.height}"
right="0"
height="475"
width="125"
/>
</s:Group>
<s:BorderContainer
backgroundColor="#000000"
height="100"
width="100%"/>
</s:Application>
so now i have set my center container's clipAndEnableScrolling to true, and problem solved
Thanks to both the stack members:)

Related

Flex conditional statement: set VGroup height according to Label Text

In my Flex code I have a Label and a VGroup container. I want to set the height of the VGroup according to the Label text.
Here is the simplified code -
<s:Group height="100%" width="100%" >
<s:Group id="titleBar" width="100%" depth="50" >
<s:Label id="titleDisplay" maxDisplayedLines="1"
color="{ColorMap.WHITE}"
color.bubble="{ColorMap.MAINTEXT}"
color.inactiveGroup="{ColorMap.MAINTEXT}"
left="10" right="35" top="1" bottom="0" minHeight="30"
verticalAlign="middle" textAlign="left"
styleName="overlayTitle"/>
</s:Group>
<s:VGroup width="100%" height="{(titleDisplay.text == "Create Pool")? "80%" : "100%"}" top="30">
<s:Group id="contentArea" width="100%" height="100%">
....
</s:Group>
</s:VGroup>
</s:Group>
So I want to set the height to 80% if the Label's text is "Create Pool", otherwise 100%.
But I am getting the following compilation error from the VGroup line -
Element type "s:VGroup" must be followed by either attribute specifications, ">" or "/>".
How to resolve this issue? I am following the code from the following link -
How i write inline conditional statement in Flex with two expressions(case)?
Please guide me how to put the conditional statement in this case.
Thanks
I resolved this issue with a custom function init().
<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
creationComplete="init()">
private function init():void
{
if (titleDisplay.text == "Create Pool")
{
contentVGroup.height = contentVGroup.height * .8;
}
}
This is perfectly working.
Thanks

How do I position a element when that container is scaled?

I have a component that I'm trying to position and it works fine when the parent is not scaled but when it is scaled the positioning is off.
How do I get the correct position?
I will try to provide some example code since it is part of a larger application but it's basically the following:
<Group id="MainGroup" x="10" y="10">
<Group id="SubGroup" x="10 y="10">
<Button id="original" x="10" y="10">
</Group>
</Group>
<Button id="clone">
Then I use the code from this question or similar code to find out how to position the second button that is outside of the scaled containers.
It looks like the code I'm using works so there must be something else going on. Here is updated test code:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" >
<fx:Script>
<![CDATA[
import com.flexcapacitor.utils.DisplayObjectUtils;
protected function button1_clickHandler(event:MouseEvent):void
{
var point:Point = DisplayObjectUtils.getDistanceBetweenDisplayObjects(originalButton, cloneButton);
cloneButton.x = point.x;
cloneButton.y = point.y;
}
]]>
</fx:Script>
<s:Group x="10" y="10" scaleX="2" scaleY="2">
<s:Group x="10" y="10">
<s:Button id="originalButton" x="10" y="10" label="Button"/>
</s:Group>
</s:Group>
<s:Button id="cloneButton" label="position me" click="button1_clickHandler(event)"/>
</s:WindowedApplication>

Width of a group in mx:ViewStack

I have a simple application:
<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" xmlns:local="*">
<mx:ViewStack width="100%" creationPolicy="all">
<s:NavigatorContent width="100%">
<local:TestGroup width="100%"/>
</s:NavigatorContent>
<s:NavigatorContent width="100%">
<local:TestGroup width="100%"/>
</s:NavigatorContent>
</mx:ViewStack>
</s:Application>
My TestGroup is a bare Spark group. It has creationComplete method, where the width of the group is traced:
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="group1_creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected function group1_creationCompleteHandler(event:FlexEvent):void
{
trace("internal group width: " + this.width)
}
]]>
</fx:Script>
</s:Group>
When I run the application, the first TestGroup has width of 1600 (which is about right), but the second one regardless of creationPolicy="all" and width="100%" is 0 (zero).
It turs out that ms:ViewStack doesn't set width for components other than the selected one.
What is the logic behind this behavior?
How can I fix it so that my second group has a real width, and I can get it at the creation complete?
You can listen to change event, that will be fired each time the selected group is changing.
Only the current active group will give you her true width, so you can do someThing like this
<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" xmlns:local="*">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected function onChange(event:Event):void
{
if(myViewStack.selectedChild){
myViewStack.selectedChild.initMyGroup();
}
}
]]>
</fx:Script>
<mx:ViewStack id="myViewStack" width="100%" creationPolicy="all" change="onChange()">
<s:NavigatorContent width="100%">
<local:TestGroup width="100%"/>
</s:NavigatorContent>
<s:NavigatorContent width="100%">
<local:TestGroup width="100%"/>
</s:NavigatorContent>
</mx:ViewStack>
</s:Application>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
public function initMyGroup():void
{
trace("internal group width: " + this.width)
}
]]>
</fx:Script>
</s:Group>
The ViewStack is a Multiple-view container. Even though having the creationComplete set to all which is by the way for Single-view containers only, Flex instantiates only the controls that are initially visible for the ViewStack. To achieve your goal, try using other containers aside from ViewStack.
More details can be found here:
http://livedocs.adobe.com/flex/3/html/help.html?content=layoutperformance_05.html
What is the logic behind this behavior?
Because there is no need to render a TestGroup element. If you set creationPlicy for all a flex container will create internal element, but it doesn't mean that the container will set size for the element.
How can I fix it so that my second group has a real width, and I can get it at the creation complete?
Use event updateComplete. Flex dispatches updateComplete events whenever the layout, position, size, or other visual characteristic of the component changes and the component is updated for display. So you will get it when second TestGroup will be selected first time.

Adding a border to a group in run time in flex

i am trying to make a group of spark type in flex at runtime.i am making a couple of buttons as children of this group in runtime. i want to add border to all group. however when i use border container it hides all other children and the stuff in group container and only shows the border container screen. How can i add border to group.
Note that i am adding the border container as a child of group container in run time.
best regards
You can add a s:Rect child at particular index acting as a border.
<?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">
<fx:Script>
<![CDATA[
import mx.graphics.SolidColorStroke;
import spark.primitives.Rect;
protected function addNewBorderButtonClick(event:MouseEvent):void
{
var borderRect:Rect = new Rect();
var solidStroke:SolidColorStroke = new SolidColorStroke(0, 3);
borderRect.stroke = solidStroke;
borderRect.percentWidth = borderRect.percentHeight = 100;
targetGroup.addElementAt(borderRect, 0);
}
]]>
</fx:Script>
<fx:Declarations>
</fx:Declarations>
<s:Group id="targetGroup"
width="100" height="100"
horizontalCenter="0" verticalCenter="0">
<!-- some visual elements here -->
<s:Button id="addNewBorderButton"
label="Add Border"
horizontalCenter="0" verticalCenter="0"
click="addNewBorderButtonClick(event)" />
</s:Group>
</s:Application>
Hope this helps,
Blaze

ListItemRenderer background color

Using flex4, I have a list with an item renderer:
<mx:List id="queueView" dataProvider="{presenter.queue.items}">
<mx:itemRenderer>
<fx:Component>
<mx:VBox>
<mx:Label text="{data.name}"/>
<mx:Label text="{data.artist.name}"/>
</mx:VBox>
</fx:Component>
</mx:itemRenderer>
</mx:List>
I have alternating colors on the list:
#queueView
{
alternating-item-colors: red, yellow;
}
but the list items always render with a white background (it renders the colors correctly if I get rid of the renderer).
If I set contentBackgroundColor="red" on the itemRenderer every item is red. The compiler won't accept transparent.
How can I make the itemRenderer respect the alternating colors of the list?
This seems to work fine for me. Here is my code:
<?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" xmlns:components="components.*">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var items:ArrayCollection = new ArrayCollection([{name:"foo",value:"bar"},
{name:"foo",value:"bar"},
{name:"foo",value:"bar"},
{name:"foo",value:"bar"},
{name:"foo",value:"bar"},
{name:"foo",value:"bar"},
{name:"foo",value:"bar"},
{name:"foo",value:"bar"}]);
]]>
</fx:Script>
<fx:Style>
#namespace s "library://ns.adobe.com/flex/spark";
#namespace mx "library://ns.adobe.com/flex/halo";
#namespace components "components.*";
#queueView
{
alternating-item-colors: red, yellow;
}
</fx:Style>
<mx:List id="queueView" dataProvider="{items}" width="200">
<mx:itemRenderer>
<fx:Component>
<mx:VBox>
<mx:Label text="{data.name}"/>
<mx:Label text="{data.value}"/>
</mx:VBox>
</fx:Component>
</mx:itemRenderer>
</mx:List>
</s:Application>
And here is the result:
What build are you running? I am running the latest beta that came out in the last few weeks. Build 4.0.0.253292 to be exact. You can try upgrading to the latest build if you haven't already and you can also try to clean your project. Also make sure your browser isn't caching the swf, which sometimes happens when the file size doesn't change dramatically.
Please let me know if I have missed something. But your code seems to work fine.