Posted on 27th March 2010 by Brian Coleman in Flex
ComboBox, Flex
I need to make a ComboBox extension someday that uses this and binds in some way. It seems pretty useful in many situations, but it’s not quite generic enough yet.
The basic functionality is this…. take an existing ComboBox that uses a dataprovider – preferably with objects of some sort, pass in a parameter that exists in the object, such as a primary key name, pass in a value that you want to match to the object parameter and finally, pass in a data object that will be pushed into the ComboBox if no value is found.
This makes sure that something is always set for a ComboBox, even if the object you expect to be set is not found for some reason.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
// sets and returns the index in a combo box for a selected field and value
// if value is not found, the data object will be pushed into the combo box
private function setComboBoxIndex(cb:ComboBox, field:String, value:*, data:*):int{
var result:int = -1;
if (value > -1){
var idx:int = 0;
for (idx=0; idx < cb.dataProvider.length; idx++){
if (cb.dataProvider[idx][field] == value){
cb.selectedIndex = idx;
return idx;
}
}
cb.dataProvider.addItemAt(data,0);
setComboBoxIndex(cb, field, value, data);
}
return result;
} |
Posted on 25th March 2010 by Brian Coleman in Linux
dpkg, grep, Linux
This probably changes with different distro – I used Ubuntu, so check for package specifics if it doesn’t work.
To check for installed software that has been installed using apt-get or similar command use this
user@computer:$ dpkg -l | grep packagename
Posted on 25th March 2010 by Brian Coleman in Flex
BitmapAsset, DragProxy, Flex, transparency
Usually drag proxies in Flex are a simple thing. You take whatever you want to drag, throw it in a bitmap asset and use it or if you are dragging and image, just use the image source directly.
However, there are cases where you need something more complex. I ran into an issue recently while trying to set a Canvas with rounded corners as the drag proxy.
The rounded corners were coming through fine, but there was a nice white background (with square corners) on the bitmap asset that wouldn’t come off.
The solution was to set transparent to true while making the bitmap asset AND to assign a background color to the asset. If you don’t assign a background color, your transparency won’t work.
I’ve seen this happen in other cases when using Flex, so when in doubt, try setting a background color, even if you don’t need it.
Here’s some sample code to create a drag proxy and the bitmap asset
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
// drag proxy which will create a thick transparent border around the bitmap asset
var dragProxy:Canvas = new Canvas();
dragProxy.width = dragInitiator.width + 15;
dragProxy.height = dragInitiator.height + 15;
dragProxy.setStyle("backgroundColor","#BBBBBB");
dragProxy.setStyle("backgroundAlpha",".5");
// the bitmap asset
var contentBitmap:BitmapAsset = new BitmapAsset();
contentBitmap.bitmapData = new BitmapData(dragInitiator.width, dragInitiator.height,true,0x000000);
contentBitmap.bitmapData.draw(dragInitiator);
contentBitmap.x = 8;
contentBitmap.y = 8;
// add the bitmap asset to the drag proxy
dragProxy.rawChildren.addChild(contentBitmap); |
Posted on 21st March 2010 by Brian Coleman in Flex
Flex, html, lineheight, measure
Text and TextArea components in Flex can be wacky. Especially when you’re trying to autosize and measure the text in them.
One area I have always had problems with is measuring HTML text height. Let’s say you have a huge font at the top, then several breaks and a smaller font.
Flex just doesn’t know how to measure that correctly and you end up either cutting text off or scrolling.
Enter this blog post – http://idletogether.com/automatically-resize-texttextarea-based-on-content-autosize-in-flex/
This tells you exactly how to go about getting started when measuring html height. I say getting started, because chances are good you’ll have to tweak something to get it to work for your situation … such as when you have containers of widely varying widths, it seems to throw things off a bit… anyway, the code is below if you don’t want to make the jump.
1
2
3
4
5
6
7
8
9
|
var ta_height:uint = 25;
field.validateNow();
for(var i:int=0; i < field .mx_internal::getTextField().numLines; i++) {
ta_height += field.mx_internal::getTextField().getLineMetrics(i).height;
}
derivedHeight = ta_height; |
Posted on 21st March 2010 by Brian Coleman in Flex
advanceddatagrid, dataprovider, errors, Flex
I love error messages that are vague and don’t really spell out what the problem is, especially when you’re first learning a new language or technology.
Most of the time a google search turns up the answer pretty quickly, but this one didn’t turn up much.
Luckily, it turned out to be a typo: I forgot to put in a couple lines while using an AdvancedDataGrid – I think anything that uses columns of data would do the same thing.
I think you can also get this error or something similar if you bind data to a dataprovider – such as dataProvider=”{myArrayCollection}” and then you also set the dataProvider in your code, such as component.dataProvider = myArrayCollection, but more then likely you’ll just an app that doesn’t load data correctly.
Anyway, the error verbatim is “Multiple initializers for property ‘dataProvider’. (note: ‘dataProvider’ is the default property of ‘mx.controls.AdvancedDataGrid’).”
So my code, using a bindable array collection (ac), looks like this.
1
2
3
4
| <mx:AdvancedDataGrid id="adgICMP" dataProvider="{ac}" width="100%" height="100%">
<mx:AdvancedDataGridColumn dataField="field1" headerText="header1" />
<mx:AdvancedDataGridColumn dataField="field2" headerText="header2"/>
</mx:AdvancedDataGrid> |
Guess what’s missing? Yep, columns. Apparently not using throws the error, but only when using bracket binding {}
1
2
3
4
5
6
| <mx:AdvancedDataGrid id="adg" dataProvider="{ac}" width="100%" height="100%">
<mx:columns>
<mx:AdvancedDataGridColumn dataField="field1" headerText="header1" />
<mx:AdvancedDataGridColumn dataField="field2" headerText="header2"/>
</mx:columns>
</mx:AdvancedDataGrid> |
If I used something like adg.dataProvider = ac in actionscript, the code would compile with no errors, although I wouldn’t get the results I wanted and it would dump out all the values in ArrayCollection