I am building an ItemRenderer in order to display a list of jobs that a company may want to carry out on a building. A user then may click on a job to select it and use add/edit/delete buttons on the parent view.
How would I highlight the selected HGroup in my s:ItemRenderer to allow a user to see which job is currently selected?
<s:Scroller width="100%" height="70%">
<s:DataGroup width="100%" height="100%"
horizontalCenter="0" verticalCenter="0"
dataProvider="{Session.EXISTING_JOBS}"
>
<s:layout >
<s:VerticalLayout />
</s:layout>
<s:itemRenderer>
<fx:Component>
<s:ItemRenderer verticalCenter="0" horizontalCenter="0" width="100%">
<fx:Script>
<![CDATA[
protected function jobSelect_clickHandler(event:MouseEvent):void
{
// highlight the HGroup here
if(this.selected == true){
jobRow.setStyle('contentBackgroundColor',0x000000);
} else {
jobRow.setStyle('contentBackgroundColor',0xFFFFFF);
}
}
]]>
</fx:Script>
<s:states>
<s:State name="normal"/>
</s:states>
<s:HGroup id="jobRow"
width="100%" height="50"
verticalAlign="middle"
click="jobSelect_clickHandler(event)" >
<s:Label text="{data.id}"
width="15%" height="50"
verticalAlign="middle"
verticalCenter="0"/>
<s:Label text="{data.company}"
width="35%" height="50"
verticalAlign="middle"
verticalCenter="0"/>
<s:Label text="{data.building}"
width="35%" height="50"
verticalAlign="middle"
verticalCenter="0"/>
<s:Label text="{data.assets}"
width="15%" height="50"
verticalAlign="middle"
verticalCenter="0"/>
</s:HGroup>
</s:ItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:DataGroup>
</s:Scroller>
Assuming that you're using the itemRenderer in a list; the List class already does this by default. You can change the value by setting the selectionColor style.
If you really want to change values on the HGroup, you can use the style contentBackgroundColor. You can tell whether your current renderer is the selected item or not by accessing the selected property of the itemRenderer instance.
protected function selectJob_clickHandler(event:MouseEvent):void
{
// highlight the HGroup here
if(this.selected == true){
hgroupID.setStyle('contentBackgroundColor',0x000000);
} else {
hgroupID.setStyle('contentBackgroundColor',0xFFFFFF);
}
}
Don't forget to add an ID to the HGroup:
<s:HGroup id="hgroupID"
width="100%" height="50"
verticalAlign="middle"
click="selectJob_clickHandler(event)" >
Related
What should be added in order to the vertical scrollbar to be visible without to be clicked or touched ? Here is image of screen :
Here is code :
<s:Scroller width="100%" height="100%">
<s:VGroup width="100%" height="100%" paddingTop="5" verticalAlign="middle" horizontalAlign="center">
<s:TextInput id="chp1" width="50%"/>
<s:TextInput id="chp2" width="50%"/>
<s:Button label="Enregistrer" click="enregistrer(event)" styleName="btn"/>
<s:Label/>
<s:Button label="Lire" click="lire(event)" styleName="btn" />
<s:TextArea id="area"/>
<s:Label/>
<s:HGroup>
<s:Button label="Envoyer" click="send(event)" styleName="btn" />
<s:Button label="Retour" click="navigator.popView()" styleName="btn" />
</s:HGroup>
<s:TextArea id="resultHTTP"/>
<s:TextInput id="h_url" text="{url}" visible="false"/>
</s:VGroup>
</s:Scroller>
As you see the vertical scrollbar at the right of the screen is not visible. So how to make it visible anytime ?
Please try this, on your scroller:
verticalScrollPolicy = "on"
Update:
What about trying this:
interactionMode="mouse"
;)
At runtime when I click the Lire button then the TextArea field under it is populated from a sharedobject data and the display becomes bigger :
Here is code :
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark" title=""
creationComplete="creationCompleteHandler(event)" >
...
<s:VGroup width="100%" height="100%" paddingTop="5" verticalAlign="middle" horizontalAlign="center">
<s:TextInput id="chp1" width="50%"/>
<s:TextInput id="chp2" width="50%"/>
<s:Button label="Enregistrer" click="enregistrer(event)" />
<s:Label/>
<s:Button label="Lire" click="lire(event)" />
<s:TextArea id="area"/>
<s:Label/>
<s:HGroup>
<s:Button label="Envoyer" click="send(event)" />
<s:Button label="Retour" click="navigator.popView()" />
</s:HGroup>
<s:TextArea id="resultHTTP"/>
<s:TextInput id="h_url" text="{url}" visible="false"/>
</s:VGroup>
How to enable vertical scroll then to view others components at the bottom ?
wrap your VGroup with a scroller. something like this:
's:Scroller width="100%" height="100%"
s:VGroup width="100%" height="100%" paddingTop="5" verticalAlign="middle" horizontalAlign="center"'
In my code, I have a list made up of items from a dataprovider. The itemRenderer for the list consists of a BorderContainer with text in it. I'm mimicking a row of buttons on a scrolling list. I'd like the cursor to change to the hand cursor as it passes over the "button", but the pointer only changes in the part of the BorderContainer that isn't covered by the text.
I've set the buttonMode to true for the list, the BorderContainer, and the text, so why isn't the cursor changing when passing over the text?
This is the list code
<s:List id="listProject" width="100%" height="100%" horizontalScrollPolicy="off" allowMultipleSelection="false"
click="listProject_clickHandler(event)" itemRenderer="ProjectRenderer"
dataProvider="{listProjects}" creationComplete="listProject_creationCompleteHandler(event)" buttonMode="true">
And this is the renderer
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
autoDrawBackground="true">
<!--<s:Label text="{data.header}"/>-->
<s:states>
<s:State name="normal"/>
<s:State name="hovered"/>
<s:State name="selected"/>
</s:states>
<!--<s:Image source.normal="{data.image1}" source.hovered="{data.image2}"/>-->
<s:BorderContainer width="200" height="50" backgroundColor="{data.color}"
borderColor.selected="#FFFFFF" borderVisible.normal="false"
borderVisible.selected="true" borderWeight.selected="4" borderStyle.selected="inset" buttonMode="true">
<s:layout>
<s:HorizontalLayout verticalAlign="middle" horizontalAlign="center"/>
</s:layout>
<mx:Text width="200" text="{data.header}" selectable="false"
color="#FFFFFF" fontSize="15" fontWeight="bold" leading="0" textAlign="center" buttonMode="true" useHandCursor="true"/>
</s:BorderContainer>
</s:ItemRenderer>
Just use a Spark Label instead of mx:Text and you'll be fine.
Also, there's some redundancy in your code. I took the liberty of trimming it down a little:
<s:BorderContainer width="200" height="50" backgroundColor="{data.color}"
borderColor.selected="#FFFFFF" borderVisible.normal="false"
borderVisible.selected="true" borderWeight.selected="4"
borderStyle.selected="inset" buttonMode="true">
<s:Label text="{data.label}" color="#FFFFFF" fontSize="15" fontWeight="bold"
horizontalCenter="0" verticalCenter="0"/>
</s:BorderContainer>
This will also fix that nasty jumpiness of the text when hovered or selected.
As soon as you do not need interaction with mx:Text, you can set mouseChildren property of its parent to false. It will fix the problem. Here is a short example:
<s:ItemRenderer>
<s:BorderContainer width="200" buttonMode="true" useHandCursor="true" mouseChildren="false">
<mx:Text text="No many text" selectable="false" />
</s:BorderContainer>
</s:ItemRenderer>
i have my hGroups as like
<s:HGroup width="100%" verticalAlign="baseline" id="Scale">
<s:Label width="80" text="Scale:" fontWeight="bold" textAlign="right"/>
<s:DropDownList id="scaleDropdown" minWidth="155" change="handleScaleDropdownChange(event)"/>
</s:HGroup>
<s:HGroup width="100%" verticalAlign="baseline" id="Precision">
<s:Label width="80" text="Precision:" fontWeight="bold" textAlign="right"/>
<s:DropDownList id="precisionDropdown" minWidth="155" change="handlePrecisionDropdownChange(event)"/>
</s:HGroup>
<s:HGroup width="100%" verticalAlign="baseline" id="Units">
<s:Label width="80" text="Units:" fontWeight="bold" textAlign="right"/>
<s:DropDownList id="unitDropdown" minWidth="155" change="handleUnitDropdownChange(event)"/>
</s:HGroup>
and i m trying to hide the hgroups on a condition when this bean tagInfoData have a value "notworking" otherwise it will shown..
should i need to write code in the creation complete as all this is in a pop up window of the button click event
i m using this
if(tagInfoData.selectionType.match("notworking"))
{
Scale.visible=true;
Precision.visible=true;
Units.visible=true;
}
else
{
Scale.visible=false;
Precision.visible=false;
Units.visible=true;
}
In each of the HGroups you want to hide, add visible="{myFunc(tagInfoData)}"
Then define:
internal function myFunc(tagInfoData:whateverTypeItIs):Boolean{
return ! tagInfoData.selectionType.match("notworking")
}
Make sure tagInfoData is defined as [Bindable]
i have an HGroup that contains a DataGroup with an ArrayCollection for a dataProvider.
the DataGroup has a VScrollBar attached to it.
how can i make sure that whenever new rows are added to the ArrayCollection, the dataGroup will scroll down ?
this window is gonna be used for a chat application so whenever new rows are added i need to see the new rows.
i know that i can perform the following command to scroll down: chatScrollBar.value=chatScrollbar.maximum
but what event do i need to attach to in order to run this command whenever a new row is visible ?
<s:HGroup width="100%">
<s:DataGroup id="vertView"
clipAndEnableScrolling="true" width="100%" height="60"
dataProvider="{chatMessages}">
<s:itemRenderer>
<fx:Component>
<s:ItemRenderer width="100%" height="8">
<s:states>
<s:State name="normal" />
<s:State name="hovered" />
</s:states>
<s:RichText text="{ data }" textAlign="left" paddingLeft="2" color="black" color.hovered="blue"/>
</s:ItemRenderer>
</fx:Component>
</s:itemRenderer>
<s:layout>
<s:VerticalLayout useVirtualLayout="true"/>
</s:layout>
</s:DataGroup>
<s:VScrollBar id="chatScrollBar" viewport="{vertView}"
height="{vertView.height}" />
</s:HGroup>
You have to set the verticalScrollPosition. See here or here. Or try this for a Spark List:
<s:List id="list"
horizontalCenter="0"
verticalCenter="0">
<s:layout>
<s:VerticalLayout id="vLayout" requestedRowCount="4"
verticalScrollPosition="{vLayout.maxScrollPosition}" />
</s:layout>
</s:list>
Try using Scroller, I think it is as simple as:
<s:Scroller >
<s:HGroup>
...
</s:HGroup>
</s:Scroller>
You shouldn't need to hook up your own scrollbar.