Flex: Backgroundimage not showing in list - apache-flex

I have a custom component that has an background image.
But when you generate this component by an ItemRenderer in a List, the background image is gone.
What am I doing wrong?
Here is an image. The first element is not generated in a list and has a background image. The other three are part of a List and have no background image.
Here is the code of the MXML of the List
<mx:VBox>
<solutionItems:displaySolutionItem /> <!-- This element shows the background image -->
<mx:List selectable="false"
useRollOver="false"
id="listControllers"
backgroundAlpha="1"
dataProvider="{controllers}" >
<mx:itemRenderer>
<fx:Component>
<solutionItems:displaySolutionItem /> <!-- These elements have nog background image -->
</fx:Component>
</mx:itemRenderer>
</mx:List>
</mx:VBox>
And here is the code of <solutionItems:displaySolutionItem />
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas
xmlns:mx="http://www.adobe.com/2006/mxml"
backgroundImage="{itemBackGround}"
backgroundSize="100%">
<mx:Script>
<![CDATA[
[Bindable]
[Embed(source="assets/Components/ContainerBackgrounds/BoxBg.png", scaleGridLeft="5", scaleGridRight="50", scaleGridTop="5", scaleGridBottom="50")]
private var itemBackGround:Class;
]]>
</mx:Script>
<mx:VBox
paddingBottom="10"
paddingLeft="10"
paddingRight="10"
paddingTop="10">
<mx:CheckBox id="chbControllerItem" label="NSL-4601" styleName="titleRed" />
<mx:HBox>
<mx:Image width="67" height="50" id="loader1" source="#Embed(source='assets/Components/ContainerBackgrounds/BoxBg.png')"/>
<mx:HBox>
<mx:VBox>
<mx:Label text="Cube size" styleName="formLabel" height="12" />
<mx:Label text="Cube config" styleName="formLabel" height="12" />
<mx:Label text="Display res" styleName="formLabel" height="12" />
<mx:Label text="DPI" styleName="formLabel" height="12" />
<mx:Label text="Price" styleName="formLabel" height="12" />
</mx:VBox>
<mx:Box>
<mx:Label text="50''" height="12" />
<mx:Text text="2x3 (1224mm x 3264mm)" height="12" />
<mx:Label text="WXGA (1360x768)" height="12" />
<mx:Label text="72 dpi" height="12" />
<mx:Label text="€ 101.000,00" height="12" />
</mx:Box>
</mx:HBox>
</mx:HBox>
</mx:VBox>
</mx:Canvas>
It is probably something small, but I can not find it.

The following will get around the problem:
Remove the backgroundImage="{itemBackGround}" from the Canvas element of the itemRenderer
Add the following before the VBox in the itemRenderer class. I tested it out and it works fine:
<mx:Canvas width="100%" height="100%" backgroundImage="{itemBackGround}" backgroundSize="100%"/>
If your find a better way, sure update your question to let us know,
Brian

Have you tried setting the alpha, or backgroundAlpha properties on your List or perhaps in the itemRenderer?
I'm guessing that the List is either drawing something on top of the background, or preventing the background from being drawn. You'd have to step through code to know for sure, though.

I didn't try this, but look like
component is not creating multiple instance/copies of image for each renderer
possible solution may be is, load image in any Singleton/Constant Class like in Model and NOT in component/list and use Model's attribute reference in component/list i.e. one copy for all renderer.
Hopes this works

Related

flex <mx:List> is hidden by other UI component

In flex UI, my <mx:list> can not be shown completely because of other component shelterring (for example: the refresh button shelter part of it ). How can I make the <mx:list> in front of all other UI component.
This is my code:
<s:HGroup verticalAlign="middle">
<s:Label text="Choose Log File"/>
<mx:ComboBox id ="logFileChooseCombo" dataProvider="{fileNameList}" width="150" color="0x000000"
close="changeLogFilesHandler(event);"/>
<mx:Spacer width="320" />
<s:Label text="Filter or HighLight:" />
<mx:ComboBox id ="filterChooseCombo" dataProvider="{filterOrHighlight}" width="150" color="0x000000"/>
<s:VGroup height="25">
<s:TextInput id="logContentInput" change="filterLogContent()"
enabled="true"
focusIn="clearMyTextInput()"
text="Filter/HightLight"
width="250" height="26"/>
**<mx:List id="searchMsgList"** x="65" y="35" width="200" height="200" fontSize="12"
change="itemChangEvent(event);" />
</s:VGroup>
</s:HGroup>
</mx:Canvas>
<s:HGroup verticalAlign="middle">
<s:Label text="Filter By Log Level:"/>
<mx:ComboBox id ="logLevelCombo" dataProvider="{logLevelsInt}" width="150" color="0x000000"
close="changeLogLevelHandler(event);"/>
<s:CheckBox id="showStack" click="showStackTrace(event)" selected="false"/>
<s:Label text="show stackTraces"/>
<mx:Spacer width="550" />
<s:Button id="test" label="refresh2">
</s:Button>
</s:HGroup>
You have a lot going on, with a mix of nested layouts and a mix of Halo and Spark containers. I'm not sure what layout you're trying to create.
That said, take a look at the swapChildren method. Something like this should work:
this.swapChildren(refresh2, searchMsgList);
But it will most likely hide your refresh button, which seems less than ideal.
A few things strike me:
Inside your first VGroup you have x and y values specified. I thought those values were ignored inide VGroups, which automatically position your children in a vertical line.
I see an closing </mx:Canvas> tag, but not an opening canvas tag. It is unusual to me to use a canvas among all the HGroups and VGroups.

Flex custom list selection not highlighting

I want to create a custom list in Flex for an interface prototype. The list is supposed to have an image and 3 text fields. This is what I have done so far, the control displayed is what I want. But, when I click on one of the items, the item does not appear (visually) to be selected. I was not sure how I would implement this.
Here is my code so far:
<s:List width="400" height="220"
dataProvider="{arrColl}"
alternatingItemColors="[#EEEEEE, white]">
<s:itemRenderer>
<fx:Component>
<mx:Canvas height="100">
<mx:Image height="90" width="120" source="{data.imageSource}"></mx:Image>
<mx:Label left="125" y="10" text="{data.title}" />
<mx:Label left="125" y="30" text="{data.type}" />
<mx:Label left="125" y="50" text="{data.description}" />
</mx:Canvas>
</fx:Component>
</s:itemRenderer>
</s:List>
Not sure what kind of graphic your data.imageSource is. Perhaps the Image is masking the highlight. Can you try making it the backgroundImage of the Canvas? Also, I've noticed that using PNG or JPG images in lists and grids can mask highlight colors. They also can prevent mouseclicks from reaching the listItem. If possible try using a SWF with vector graphics.
For anyone else, who is stuck and on the same boat - this is what I did and it works now:
<mx:List width="400" height="220"
dataProvider="{arrColl}"
alternatingItemColors="[#EEEEEE, white]">
<mx:itemRenderer>
<fx:Component>
<mx:Canvas height="100">
<mx:Image height="90" width="120" source="{data.imageSource}"></mx:Image>
<mx:Label left="125" y="10" text="{data.title}" fontWeight="bold" />
<mx:Label left="125" y="30" text="{data.type}" fontStyle="italic" />
<mx:Label left="125" y="50" text="{data.description}" />
</mx:Canvas>
</fx:Component>
</mx:itemRenderer>
</mx:List>
Note: The difference is the List and itemRenderer are from the mx namespace rather than the s namespace.

Issues displaying the Background in VBox while using WindowShader

I am using a WindowShader in my website. every thing is working fine. but for somereason i am unable to display any background for my "home_feeds" VBox. If i add components on it, i can see them. But they backgound is not working. Even if i remove every thing from the Canvas(with home_feeds) i still dont see any background. But if i remove the comments from my mx:List.. i can see the background.
my code is given below
<mx:VBox right="35" paddingRight="10" verticalAlign="top" horizontalAlign="right">
<containers:WindowShade id="shade" opened="false" openIcon="{null}" closeIcon="{null}" paddingTop="0"
headerLocation="bottom" visible="true">
<containers:headerRenderer>
<mx:Component>
<flexlib:CanvasButton width="100%" height="20" skin="mx.skins.ProgrammaticSkin">
<mx:Script>
<![CDATA[
import flexlib.containers.WindowShade;
]]>
</mx:Script>
<mx:Box width="100%" horizontalAlign="center">
<degrafa:Surface width="80">
<degrafa:GeometryGroup>
<geometry:EllipticalArc closureType="pie"
arc="180" startAngle="-180" width="80" height="35" y="-18">
<geometry:fill>
<paint:GradientFill angle="90">
<paint:GradientStop color="#920000" />
<paint:GradientStop color="#D31F1F" />
</paint:GradientFill>
</geometry:fill>
</geometry:EllipticalArc>
<geometry:Polygon>
<geometry:data>40,5 35,13 45,13</geometry:data>
<geometry:stroke>
<paint:SolidStroke color="#333333" alpha="{WindowShade(parent).opened ? 1 : 0}" weight="1" />
</geometry:stroke>
<geometry:fill>
<paint:SolidFill color="#ffffff" alpha="{WindowShade(parent).opened ? 1 : 0}" />
</geometry:fill>
</geometry:Polygon>
<geometry:Polygon>
<geometry:data>40,13 35,5 45,5</geometry:data>
<geometry:stroke>
<paint:SolidStroke color="#333333" alpha="{WindowShade(parent).opened ? 0 : 1}" weight="1" />
</geometry:stroke>
<geometry:fill>
<paint:SolidFill color="#ffffff" alpha="{WindowShade(parent).opened ? 0 : 1}" />
</geometry:fill>
</geometry:Polygon>
</degrafa:GeometryGroup>
</degrafa:Surface>
</mx:Box>
</flexlib:CanvasButton>
</mx:Component>
</containers:headerRenderer>
<mx:Canvas horizontalScrollPolicy="off" width="200" height="350" >
<!--mx:List id="home_feeds" height="100%" width="100%" itemRenderer="file_manager.list_item_template" doubleClickEnabled="true" /-->
<mx:VBox id="home_feeds"
width="100%"
backgroundAlpha="0.1"
left="10"
right="10">
</mx:VBox>
</mx:Canvas>
<containers:filters>
<mx:DropShadowFilter alpha=".3" angle="90" />
</containers:filters>
</containers:WindowShade>
</mx:VBox>
Kindly let me know what am i doing wrong here.... And how can i fix it. I want to use the VBox there.
Regards
Zeeshan
The size of a VBox without an explicit value for width would be zero if it doesn't have any children in it. Add some children (a Label for example) to see the background color. Increase background alpha from 0.1 to 0.5 or something to see it clearly.
If you mention explicit values for width and height (instead of percentages), you can see the background color even if it doesn't have any children.
set backgroundColor="#00ff00" (green) for the home_feeds VBox to differentiate VBox's background color from its parent's color.

How can I bind a flex component's height to the height of the browser window?

I want to constrain the height of a flex component to the height of the browser viewport.
The component's children are populated from a database table using a repeater, and are basic checkboxes. There are enough of them that the flex app ends up being about twice the height of the screen, which means some of the rest of the layout goes crappy on me. How can I force the component that contains these to limit itself to the size of the viewport?
Setting the components height to 100% should be all you need.
in mxml:
<mx:Vbox height="100% />
in actionscript:
myVBox.percentHeight = 100;
if the contents of the component take up more space than available on screen the component should provide its own scroll bars keeping the component the same height. If this is not the case it would help if you posted code.
Set minHeight and minWidth for your container to 0:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="100%" height="100%">
<mx:HBox width="100%" height="100%">
<mx:HBox width="20%" height="100%">
<mx:Label text="Left Panel"/>
</mx:HBox>
<mx:VBox width="100%" height="100%" minWidth="0" minHeight="0">
<mx:CheckBox label="1" />
<mx:CheckBox label="2" />
<mx:CheckBox label="3" />
<mx:CheckBox label="4" />
<mx:CheckBox label="5" />
<mx:CheckBox label="6" />
<mx:CheckBox label="7" />
<mx:CheckBox label="8" />
<mx:CheckBox label="9" />
<mx:CheckBox label="10" />
<mx:CheckBox label="11" />
<mx:CheckBox label="12" />
<mx:CheckBox label="13" />
<mx:CheckBox label="14" />
<mx:CheckBox label="15" />
<mx:CheckBox label="16" />
<mx:CheckBox label="17" />
<mx:CheckBox label="18" />
<mx:CheckBox label="19" />
<mx:CheckBox label="20" />
</mx:VBox>
<mx:HBox width="20%" height="100%">
<mx:Label text="Right Panel"/>
</mx:HBox>
</mx:HBox>
</mx:Application>
If I understand your question you want to get the size of the client area of the browser window which is the same as the size of your Flex app.
So, just use Application.application.width and Application.application.height
You should listen to the event that changes the app size and make a comparison like
if (component.width > Application.application.width)
component.width = Application.application.width
The event would probably be stage.addEventListener(Event.RESIZE, onStageResize)
You can set you component to the height of the viewport
say:
ActionScript:
component.height = viewport.height;
MXML:
<mx:component height={viewport.height} />

how to freeze a label in flex?

I want to have the title of my application to be freezed, that is, even if I scroll down the page, I want the label name to be in focus, at the top always.. Is that possible?
Now if I scroll down , the screen name disappears. Instead, can it be freezed like freezing columns or rows in excel?
Run this:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="100%" height="100%">
<mx:VBox width="100%" height="100%">
<mx:Label text="My Label!" />
<mx:VBox width="100%" height="100%" minWidth="0" minHeight="0">
<mx:CheckBox label="1" />
<mx:CheckBox label="2" />
<mx:CheckBox label="3" />
<mx:CheckBox label="4" />
<mx:CheckBox label="5" />
<mx:CheckBox label="6" />
<mx:CheckBox label="7" />
<mx:CheckBox label="8" />
<mx:CheckBox label="9" />
<mx:CheckBox label="10" />
<mx:CheckBox label="11" />
<mx:CheckBox label="12" />
<mx:CheckBox label="13" />
<mx:CheckBox label="14" />
<mx:CheckBox label="15" />
<mx:CheckBox label="16" />
<mx:CheckBox label="17" />
<mx:CheckBox label="18" />
<mx:CheckBox label="19" />
</mx:VBox>
<mx:Label text="Bottom label here!" />
</mx:VBox>
</mx:Application>
Set minWidth=0 and minHeight=0 so Vbox is not going to expand.
Have you tried ApplicationControlBar - use it with dock set to true.
Quoting from the linked page:
Docked mode: The bar is always at the top of the application's drawing area and becomes part of the application chrome. Any application-level scroll bars don't apply to the component, so that it always remains at the top of the visible area, and the bar expands to fill the width of the application. To create a docked bar, set the value of the dock property to true.
I don't know if I understand you correct, but I would make it the following way:
<mx:VBox width="100%" height="100%" verticalScrollPolicy="off">
<mx:Label label="My Title" />
<mx:VBox name="content">
...
</mx:VBox>
</mx:VBox>
So you'll be scrolling just the second VBox and the outer VBox with the title keeps always on top.

Resources