Posted on 14th June 2010 by Brian Coleman in Actionscript | Flex
as3, Flex, RegEx, replace, string
This is one of those standards you keep coming back to.
Using RegEx is the quickest way to replace all string values, using the /g flag to make the replace work for all instances in the string.
For something simple you’d do this
myString = myString.replace(/text to find/g, “replace text with this”);
but if there’s any special characters, remember to escape them
myString = myString.replace(/\[text to find\]/g, “replace text with this”);
Posted on 4th June 2010 by Brian Coleman in Flex
Adobe, errors, FlashBuilder, Flex
After uninstalled a Stand-alone version of Flex Builder and installing Adobe CS5 Premium which comes bundled with Flash Builder, I was treated to this lovely error message when trying to debug an app that had previously worked fine.
Installed Adobe Flash Player Is Not a Debugger
Flash Builder cannot locate the required debugger version of Adobe Flash Player. You might need to install the debugger version of the Flash Player or reinstall Flash Builder.

Whoa there Adobe
I like to use IE as my default debugger because I never use it to browse and along with the above error, I got some funky message about IE can’t install it’s lame Active X plugin because you’ve got another version of Adobe Flash Player installed.
Well great. So after searching up a storm and finding nothing concrete, I came across an Adobe tech-note that said run the uninstaller from the command line and use the /clean option.
After trying that (and re-booting, I guess that’s crucial for IE) everything’s back to working. When installing the next version of the Flash Player and related plug-ins nothing will choke because everything’s been wiped out.
If you need the uninstaller link, here’s the always current version – http://download.macromedia.com/pub/flashplayer/current/uninstall_flash_player.exe
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 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; |