How to increase horizontalgridline thickness in Flex 3 - actionscript-3

i have set horizontal gridlines between rows of a datagrid to true. But i'm unable to increase its thickness. how to do it?

There are two ways you can go about solving this. If you check the docs, DataGrid has a horizontalSeparatorSkin style. The docs state that this is undefined by default, and in which case the grid uses it's drawHorizontalLine() method to draw the lines.
So you can either set the horizontalSeparatorSkin style to your own class that extends ProgramaticSkin or extend the DataGrid class and override the drawHorizontalLine() method. Both are fairly easy to do, here's app with an example of each one:
App
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:local="*"
layout="vertical"
creationComplete="onCreationComplete()">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
protected function onCreationComplete():void
{
var dp:ArrayCollection= new ArrayCollection([ { label: "one", value: 1 }, { label: "two", value: 2 }, { label: "three", value: 3 } ]);
grid.dataProvider=dp;
customGrid.dataProvider=dp;
}
]]>
</mx:Script>
<mx:DataGrid id="grid" horizontalGridLines="true" horizontalSeparatorSkin="{HorizontalSeparatorSkin}">
<mx:columns>
<mx:DataGridColumn dataField="label" />
<mx:DataGridColumn dataField="value"/>
</mx:columns>
</mx:DataGrid>
<local:CustomGrid id="customGrid" horizontalGridLines="true" horizontalGridLineColor="#FF0000">
<local:columns>
<mx:DataGridColumn dataField="label" />
<mx:DataGridColumn dataField="value"/>
</local:columns>
</local:CustomGrid>
</mx:Application>
Programatic skin (HorizontalSeparatorSkin.as):
package
{
import flash.display.Graphics;
import mx.skins.ProgrammaticSkin;
public class HorizontalSeparatorSkin extends ProgrammaticSkin
{
public function HorizontalSeparatorSkin()
{
super();
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
// draw a line at the bottom of the rectangle defined by
// unscaledWidth and unscaledHeight
var g:Graphics = this.graphics;
g.clear();
g.lineStyle(3, 0x00FF00); // change thickness / color here
g.moveTo(0,unscaledHeight);
g.lineTo(unscaledWidth, unscaledHeight);
}
}
}
Custom grid (CustomGrid.as):
package
{
import flash.display.Graphics;
import flash.display.Sprite;
import mx.controls.DataGrid;
import mx.controls.listClasses.ListBaseContentHolder;
public class CustomGrid extends DataGrid
{
public function CustomGrid()
{
super();
}
override protected function drawHorizontalLine(s:Sprite, rowIndex:int, color:uint, y:Number):void
{
var contentHolder:ListBaseContentHolder = s.parent.parent as ListBaseContentHolder;
var g:Graphics = s.graphics;
g.lineStyle(3, color); // change the thickness here
g.moveTo(0, y);
g.lineTo(contentHolder.width, y);
}
}
}

Related

AdvancedDataGridColumnGroup cell color

How to specify the color of the text inside a particular cell contained in AdvancedDataGridColumnGroup in Flex? The code is in action script and the text color varies according to the value that the cell contains. i.e. if it is negative value it has to be displayed in red otherwise black.
Please mention if there is any work around too!
Thanks!
I've done example with functionality that you describe. Hope, it will help.
<mx:AdvancedDataGrid id="grid"
itemRenderer="MyAdvancedDataGridItemRenderer"
dataProvider="{dataProvider}"
width="200" height="100%">
<mx:groupedColumns>
<mx:AdvancedDataGridColumn dataField="name"/>
<mx:AdvancedDataGridColumn dataField="score"/>
</mx:groupedColumns>
</mx:AdvancedDataGrid>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var dataProvider:ArrayCollection = new ArrayCollection([
{name:"Name1", score:-12},
{name:"Name2", score:10},
{name:"Name3", score:-100},
]);
]]>
</mx:Script>
</mx:Application>
And class MyAdvancedDataGridItemRenderer.as:
package
{
import mx.controls.advancedDataGridClasses.AdvancedDataGridItemRenderer;
import mx.controls.advancedDataGridClasses.AdvancedDataGridListData;
public class MyAdvancedDataGridItemRenderer extends AdvancedDataGridItemRenderer
{
public function MyAdvancedDataGridItemRenderer()
{
super();
}
override public function validateProperties():void
{
super.validateProperties();
if (listData)
{
var item:Object = AdvancedDataGridListData(listData).item;
if (AdvancedDataGridListData(listData).dataField == "score") {
setStyle("color", item.score < 0 ? 0xff0000 : 0x000000);
}
}
}
}
}

In label, value is not displaying which is used in module

I am trying to call a function (having two parameters) of module and assign values to it.
I can see the value being assigned in trace, but the same value is not displaying when it is assigned to label.
If I directly assign the value to label. It says:
Error:1009: Null object Reference
If I use [Bindable] meta tag to that label, it won't show any runtime error but the value is also not displayed. I have searched the internet and found that the [Bindable] meta tag works as try and catch blog.
How to get value display assign to label?
Main.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:custom="com.custom.*" xmlns:local="*" creationComplete="onload()">
<mx:Script>
<![CDATA[
import modules.AModule;
import mx.events.ModuleEvent;
import mx.containers.VBox;
import mx.containers.TitleWindow;
import mx.controls.TextInput;
import mx.controls.Button;
import mx.containers.HBox;
import mx.controls.Label;
import mx.events.CloseEvent;
import mx.controls.Text;
import com.custom.CustomAlert;
import mx.controls.Alert;
import mx.containers.Canvas;
import mx.events.ItemClickEvent;
import mx.core.UIComponent;
import mx.modules.ModuleManager;
import mx.modules.IModuleInfo;
import mx.containers.Box;
import mx.controls.ProgressBar;
//private var can:Canvas;
public var titlewin:TitleWindow = new TitleWindow();
public var usern:TextInput = new TextInput();
public var passw:TextInput = new TextInput();
public var vb:VBox = new VBox();
public var hb1:HBox = new HBox();
public var hb2:HBox = new HBox();
public var hb3:HBox = new HBox();
public var nc:NetConnection;
public var bt1:Button = new Button();
private var pb:ProgressBar;
private var progressContainer:Box;
private var info:IModuleInfo;
private var module:UIComponent = null;
public var can:Canvas= new Canvas();
public function onload():void
{
var label1:Label= new Label();
var label2:Label= new Label();
label1.text="Username";
label2.text="Password ";
hb1.addChild(label1);
hb1.addChild(usern);
hb2.addChild(label2);
hb2.addChild(passw);
vb.addChild(hb1);
vb.addChild(hb2);
bt1.label="Sign In";
hb3.addChild(vb);
hb3.addChild(bt1);
titlewin.addChild(hb3);
//Title Window creation starts here
titlewin.title="Login";
titlewin.setStyle("paddingLeft",20);
titlewin.setStyle("paddingRight",20);
titlewin.setStyle("paddingTop",20);
titlewin.setStyle("paddingBottom",20);
titlewin.setStyle("borderThicknessBottom",0);
titlewin.setStyle("borderThicknessLeft",0);
titlewin.setStyle("borderThicknessRight",0);
titlewin.setStyle("borderThicknessTop",0);
titlewin.setStyle("cornerRadius",0);
titlewin.setStyle("borderColor","#D20101");
this.addChild(titlewin);
viewStack.enabled=false;
ctbb.enabled=false;
bt1.addEventListener(MouseEvent.CLICK, netconn);
}
private function onclick():void
{
if(usern.text!="")
{
this.removeChild(titlewin);
viewStack.enabled=true;
ctbb.enabled=true;
username.text=usern.text;
}
else
{
Alert.show("Please enter Username");
}
}
private function netconn(event:MouseEvent):void
{
nc = new NetConnection();
nc.connect("rtmp://localhost/loginhere",usern.text);
nc.addEventListener(NetStatusEvent.NET_STATUS, onstatushandler);
}
private function onstatushandler(event:NetStatusEvent):void
{
if(event.info.code=="NetConnection.Connect.Success")
{
status.text="Connected";
onclick();
}
if(event.info.code=="NetConnection.Connect.Rejected")
{
status.text="Rejected";
}
if(event.info.code=="NetConnection.Connect.Failed")
{
status.text="Failed";
}
}
private function JoinClick(event:MouseEvent):void{
if(viewStack.numChildren==3)
{
Alert.show("You Cant Add More Button","Alert");
}
if(viewStack.numChildren<3)
{
if(viewStack.numChildren<2)
{
can.label="Button2";
var button1:CustomButton= new CustomButton();
button1.label="Leave Table";
button1.x=300;
button1.y=200;
var txt:Text = new Text();
txt.text=can.label;
txt.x=50;
txt.y=50;
button1.addEventListener(MouseEvent.CLICK,remove2);
can.addChild(button1);
can.addChild(txt);
loadmodule();
}
else
{
can.label="Button3";
var button2:CustomButton= new CustomButton();
button2.label="Leave Table";
button2.x=300;
button2.y=200;
button2.addEventListener(MouseEvent.CLICK,remove3);
can.addChild(button2);
var txt1:Text = new Text();
txt1.text=can.label;
txt1.x=50;
txt1.y=50;
can.addChild(txt1);
}
can.setStyle("backgroundColor","0x5EA5BA");
viewStack.addChild(can);
if(viewStack.numChildren>2)
{
viewStack.selectedIndex=2;
}
else
{
viewStack.selectedIndex=1;
}
}
}
private function remove2(event:MouseEvent):void{
Alert.show("Do you want to Leave Table?","Confirmation",Alert.YES|Alert.NO,this,closeAlert2);
}
private function closeAlert2(event:CloseEvent):void{
if(event.detail==Alert.YES)
{
viewStack.removeChildAt(1);
}
}
private function remove3(event:MouseEvent):void{
if(viewStack.numChildren>2)
{
Alert.show("Do You want to leave Table?","Confirmation",Alert.YES|Alert.NO,this,closeAlert3);
}
else
{
Alert.show("Do you want to Leave Table?","Confirmation",Alert.YES|Alert.NO,this,closeAlert1);
}
}
private function closeAlert1(event:CloseEvent):void{
if(event.detail==Alert.YES)
{
viewStack.removeChildAt(1);
}
}
private function closeAlert3(event:CloseEvent):void{
if(event.detail==Alert.YES)
{
viewStack.removeChildAt(2);
}
}
private function loadmodule():void
{
pb = new ProgressBar();
pb.labelPlacement = "center";
pb.label = "Loading %3 %";
progressContainer = new Box();
progressContainer.percentWidth = 100;
progressContainer.percentHeight = 100;
progressContainer.setStyle("horizontalAlign", "center");
progressContainer.setStyle("verticalAlign", "middle");
progressContainer.addChild(pb);
can.addChild(progressContainer);
var moduleUrl:String="../bin-debug/modules/useModule.swf";
info=ModuleManager.getModule(moduleUrl);
if(info!=null)
{
info.addEventListener(ModuleEvent.READY, modEventHandler);
info.addEventListener(ModuleEvent.ERROR,modErrorHandler);
info.load();
}
}
private function modEventHandler(e:ModuleEvent):void
{
info.removeEventListener(ModuleEvent.READY, modEventHandler);
info.removeEventListener(ModuleEvent.ERROR, modErrorHandler);
can.removeAllChildren();
if(module==null)
{
module = info.factory.create() as UIComponent;
if(module!=null)
{
module.x=0;
module.y=0;
module.percentWidth=100;
module.percentHeight=100;
can.addChild(module);
if(module is AModule)
{
}
}
}
}
private function modErrorHandler(event:ModuleEvent):void {
//cleanup and display an error alert
info.removeEventListener(ModuleEvent.READY, modEventHandler);
info.removeEventListener(ModuleEvent.ERROR, modErrorHandler);
info = null;
Alert.show(event.toString(), "Error Loading Module");
unloadModule();
}
private function unloadModule():void
{
can.removeAllChildren();
if (module != null && info != null) {
info.addEventListener(ModuleEvent.UNLOAD, unloadEventHandler);
info.unload();
}
}
private function unloadEventHandler(e:ModuleEvent):void
{
info.removeEventListener(ModuleEvent.UNLOAD, unloadEventHandler);
module = null;
info = null;
}
]]>
</mx:Script>
<mx:Canvas width="700" height="400" x="166" y="32">
<mx:ViewStack id="viewStack" width="100%" height="100%">
<mx:Canvas label="Button1" backgroundColor="#5EA5BA" visible="true" id="can1" >
<local:CustomButton label="Join" click="JoinClick(event)" x="536" y="222"/>
<mx:Label x="304" y="120" text="Label" id="username"/>
<mx:Label x="304" y="55" text="Label" id="status"/>
</mx:Canvas>
</mx:ViewStack>
</mx:Canvas>
<custom:CustomControlBar x="166" y="423" id="ctbb">
<custom:CustomToggleButtonBar dataProvider="viewStack"/>
</custom:CustomControlBar>
</mx:Application>
useModule.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="508" height="218" implements="modules.AModule" backgroundColor="#F00F0F" creationComplete="addlabel();">
<mx:Script>
<![CDATA[
import mx.core.Application;
public var logsin:loginhere = new loginhere();
public function addlabel():void
{
lb1.text=logsin.username.text;
txt3.text=logsin.username.text;
trace(txt3.text);
trace(lb1.text);
}
]]>
</mx:Script>
<mx:TextInput id="txt3" x="30.5" y="10" width="79"/>
<mx:Label id="lb1" x="31.5" y="40" width="78" text="Will it Change?"/>
</mx:Module>
AModule.as (Its an interface)
package modules
{
import flash.events.IEventDispatcher;
public interface AModule extends IEventDispatcher
{
function addlabel():void;
}
}
I haven't looked through the entire code, but one thing I noticed is that you should pass the values on as parameters to the child components and use data binding to dynamically update parameters.
So in AModule.as:
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="508" height="218" implements="modules.AModule" backgroundColor="#F00F0F" creationComplete="addlabel();">
<mx:Script>
<![CDATA[
import mx.core.Application;
public var logsin:loginhere = new loginhere();
[Bindable]
public var username:String = "";
]]>
</mx:Script>
<mx:TextInput id="txt3" text="{username}" x="30.5" y="10" width="79"/>
<mx:Label id="lb1" text="{username}" x="31.5" y="40" width="78" text="Will it Change?"/>
</mx:Module>
In the method where you create the module you can then:
module.username = //var that holds username;
The point I missed was, I dint create a instance for interface in main.mxml
The var should be created in modEventHandler function In that function the below lines should be added
ichild=module as AModule;
ichild.addlabel(tt.text);
so the module gets called and the value is displayed in the label field.
Please let me know, if its wrong way of working. Thank You

When using TabNavigator how to align content of dynamically added tab

Given a simple example:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import com.example.Tab;
private function addSecondTab(event:Event):void {
tabs.addChild(new Tab("Second"));
}
]]>
</mx:Script>
<mx:TabNavigator id="tabs" width="100%" height="100%">
<mx:VBox horizontalAlign="center" verticalAlign="middle" label="#1">
<mx:Label text="test"/>
</mx:VBox>
</mx:TabNavigator>
<mx:Button label="Add Second Tab" click="addSecondTab(event)" />
</mx:Application>
package com.example {
import mx.containers.VBox;
import mx.controls.Label;
import mx.events.FlexEvent;
public class Tab extends VBox {
public function Tab(name:String) {
label = name;
setStyle("horizontal-align", "center");
setStyle("vertical-align", "middle");
}
override protected function createChildren():void {
super.createChildren();
var box:VBox = new VBox();
box.setStyle("border-style", "solid");
box.setStyle("border-thickness", 1);
box.setStyle("border-color", 0xFF0000);
var l1:Label = new Label();
l1.text = "Hello!";
box.addChild(l1);
var l2:Label = new Label();
l2.setStyle("fontWeight", "bold");
l2.text = "This is a line of text...";
box.addChild(l2);
addChild(box);
}
}
}
Why aren't styles (border and alignment) being applied inside the second tab?
Flex only supports hyphenated style names in CSS. So in MXML or Actionscript statements you should use the camel case versions of the style names:
horizontalAlign, verticalAlign, borderStyle, etc.
You can read more about it in Adobe's documentation, in particular this section on CSS selector names.

Flex SkinnableContainer skin access Group inside contentGroup

I have skin class in which I defined a Group inside my contentGroup:
<s:Group id="contentGroup" left="0" right="0" top="0" bottom="0" minWidth="475" minHeight="0">
<s:layout>
<s:HorizontalLayout paddingLeft="0" paddingRight="0" paddingTop="0" paddingBottom="0" gap="2" />
</s:layout>
<s:Group id="group_nav_custom_comp_hgroup_prevnext" left="0" right="0" top="0" bottom="0" minWidth="100" minHeight="0">
<s:layout>
<s:HorizontalLayout paddingLeft="0" paddingRight="0" paddingTop="0" paddingBottom="0" gap="5" />
</s:layout>
<s:Button label="Test Button"/>
</s:Group>
</s:Group>
Now, in my CustomComponent that extends the skin class above I am trying to access the "group_nav_custom_comp_hgroup_prevnext" (which is the child group inside the contentGroup) so I can add elements to it at runtime:
public class GroupNavCustomContainer extends SkinnableContainer
{
private var m_group_prev_next:Group = null;
private var m_bAdded_btns:Boolean = true;
private var _prevbtn:UIComponent = null;
public function GroupNavCustomContainer()
{
super();
setStyle("skinClass", GroupNavCustomSkin);
}
//----------------------------------
public function set prevBtn(ui_comp_prev:UIComponent):void
{
if(m_group_prev_next)
{
_prevbtn = ui_comp_prev;
m_bAdded_btns = true;
invalidateProperties();
}
}
//-------------------------------------------------------------------------
override protected function partAdded(partName:String, instance:Object):void
{
trace("In partAdded");
if(partName == "contentGroup")
{
var group:Group = instance as Group;
var visualElem:IVisualElement = group.getElementAt(0);
m_group_prev_next = visualElem as Group;
}
super.partAdded(partName, instance);
}
//------------------------------------------------------------------------
override protected function commitProperties():void
{
super.commitProperties();
if (m_bAdded_btns)
{
m_bAdded_btns = false;
m_group_prev_next.addElement(_prevbtn);
}
}
}
The result is my: group_nav_custom_comp_hgroup_prevnext is just not showing up at all, evidenced by the fact that the button present in it at compile time is not visible. Anyone know how to get it to show up? - thx! -Mike
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Ok I added my sub group as a skin part:
[SkinPart(required="true")]
public var group_nav_custom_comp_hgroup_prevnext:Group;
so now I can access it from anywhere in the CustomComponent. But the button inside the 'group_nav_custom_comp_hgroup_prevnext' still doesn't show up . Any one know why?
package com.viiv.digi.views.navigation
{
import mx.core.IVisualElement;
import mx.core.UIComponent;
import skins.GroupNavCustomSkin;
import spark.components.Group;
import spark.components.SkinnableContainer;
public class GroupNavCustomContainer extends SkinnableContainer
{
private var m_group_prev_next:Group = null;
private var m_bAdded_btns:Boolean = false;
private var _prevbtn:UIComponent = null;
[SkinPart(required="true")]
public var group_nav_custom_comp_hgroup_prevnext:Group;
public function GroupNavCustomContainer()
{
super();
setStyle("skinClass", GroupNavCustomSkin);
}
//----------------------------------
public function set prevBtn(ui_comp_prev:UIComponent):void
{
_prevbtn = ui_comp_prev;
m_bAdded_btns = true;
invalidateProperties();
}
//------------------------------------
public function get prevBtn():UIComponent
{
return _prevbtn;
}
//-------------------------------------------------------------------- -----
override protected function partAdded(partName:String, instance:Object):void
{
trace("In partAdded");
super.partAdded(partName, instance);
}
//-------------------------------------------------------------------- ----
override protected function commitProperties():void
{
super.commitProperties();
if (m_bAdded_btns)
{
m_bAdded_btns = false;
group_nav_custom_comp_hgroup_prevnext.addElement(_prevbtn);
}
}
}
}
The contentGroup should contain the elements added to the SkinnableContainer, and nothing else. This is managed in the parent component, not the skin. So you would add the "group_nav_custom_comp_hgroup_prevnext" Group component definition right below the contentGroup and then reference it in the GroupNavCustomContainer.

ActionScript Item Renderer in DataGrid

I am using this example from blog.flexexamples.com.
I have a datagrid and trying to dynamically add button to one of datagrid column. But I want this Button as an ItemRenderer to be written in ActionScript and not MXML.
How can I do that ?
Thanks
I think this is what you need.
ActionButtonItemRenderer.as :
package
{
import flash.events.MouseEvent;
import mx.controls.Alert;
import mx.controls.Button;
import mx.controls.listClasses.IDropInListItemRenderer;
import mx.controls.listClasses.IListItemRenderer;
import mx.core.IFlexDisplayObject;
public class ActionButtonItemRenderer extends Button implements IFlexDisplayObject, IListItemRenderer, IDropInListItemRenderer
{
public var btn:Button;
public function ActionButtonItemRenderer()
{
super();
btn = new Button();
btn.label = "Take Action";
btn.addEventListener(MouseEvent.CLICK,clickHandler);
btn.visible = btn.includeInLayout = true;
}
override protected function clickHandler(event:MouseEvent):void
{
super.clickHandler(event);
Alert.show("Button clicked");
}
}
}
DynamicDataGridButton.mxml :
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600">
<mx:ApplicationControlBar dock="true">
<mx:Button label="Add column" click="init();" />
</mx:ApplicationControlBar>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var arr:ArrayCollection = new ArrayCollection
(
[
{fname:'A',lname:'B'},
{fname:'C',lname:'B'},
{fname:'D',lname:'B'}
]
);
private function addDataGridColumn(dataField:String):void {
var dgc:DataGridColumn = new DataGridColumn(dataField);
dgc.itemRenderer = new ClassFactory(ActionButtonItemRenderer);
var cols:Array = dg.columns;
cols.push(dgc);
dg.columns = cols;
}
private function init():void {
addDataGridColumn("Details");
}
]]>
</mx:Script>
<mx:DataGrid id="dg" dataProvider="{arr}">
<mx:columns>
<mx:DataGridColumn id="dgc1" dataField="fname" headerText="First Name"
width="75"/>
<mx:DataGridColumn id="dgc2" dataField="lname" headerText=" Last Name"
width="150"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>
To dynamically create a button in AS3 syntax you would do this:
var button:Button = new Button();
Then after you've created the button, you can set it's properties like this:
button.label = "Click Me!";
And lastly you would add it to one of your items as such:
var dp:Array = [{label: "Button 1", button: button},{label: "Button 2", button: button}];
myDg.dataProvider = dp;
Then you would feed it to your datagrid that is laid out like this:
<mx:DataGrid id="myDG" variableRowHeight="true">
<mx:columns>
<mx:DataGridColumn dataField="label" headerText="Labels"/>
<mx:DataGridColumn dataField="button" headerText="Buttons"/>
</mx:columns>
</mx:DataGrid>
Not sure if that would actually work though, you may have to have an button itemRenderer on the entire column like this example.