Flex DragProxy for container with rounded corners

1 comment

Posted on 25th March 2010 by Brian Coleman in Flex

, , ,

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);

Measuring HTML line height in Flex

1 comment

Posted on 21st March 2010 by Brian Coleman in Flex

, , ,

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;

Flex – Multiple initializers

2 comments

Posted on 21st March 2010 by Brian Coleman in 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

SQL Last Updated Trigger

0 comments

Posted on 21st March 2010 by Brian Coleman in SQL

This will no doubt be old hat for anyone who’s worked with SQL, but the other day I was going through some code snippets and came across this little gem.
I know I got it off a blog post somewhere, but never recorded where, so to anyone who’s ever posted this…Thanks!

This is pretty generic, if you only want to update the date when a certain field changes, you’ll have to modify a bit.
But if all you want is a field that updates every time a row updates, then this is your trigger.

SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[NameOfTable]
ON [dbo].[NameOfTable]
FOR UPDATE
AS
BEGIN
    IF NOT UPDATE(datefieldname)
       UPDATE dbo.NameOfTable SET datefieldname=GETDATE()
       WHERE id IN (SELECT id FROM inserted)
END

Symbolic Links

0 comments

Posted on 20th March 2010 by Brian Coleman in Linux

, , ,

Symbolic Links are used in Linux (and UNIX I guess) to point to a file or directory from within another directory. Like a shortcut in Windows.
When developing on my new Linux box, especially when SSH’d in, I need symbolic links, for example to restart apache quickly or point to put a pointer in my public_html directory pointing to my drupal install that’s somewhere else.

Although my setup doesn’t involve multiple filesystems yet, these links can even go across filesystems to run programs on other mounts.

Before making a link, to restart apache I’d have to run this

user@computer:$ /etc/init.d/apache2 restart

After making a new link called apache in my bin dir like this

user@computer:$ ln -s /etc/init.d/apache2 /bin/apache

I can now restart apache using this

user@computer:$ apache restart

Ooooo so many keystrokes saved, eh? Ok I admit it, I just wanted to play with the terminal plugin for http://wordpress.org/extend/plugins/wp-syntax/
Amazing indeed

Page 2 of 3123