Ever wanted to check in Flex whether all the public members of an object are the same? You can use the ObjectToString method in that case:
public class SerializeUtil
{
public static function ObjectToString(object: *): String
{
var ba: ByteArray = new ByteArray();
ba.writeObject(object);
return ba.toString();
}
public static function ObjectToByteArray(object: *): ByteArray
{
var ba: ByteArray = new ByteArray();
ba.writeObject(object);
ba.position = 0;
return ba;
}
}
To do the actual comparison:
if (SerializeUtil.ObjectToString(object1)==SerializeUtil.ObjectToString(object2))
{
// Objects are 'equal'
}
else
{
// Objects are not 'equal'
}
Monday, April 21, 2008
Thursday, February 14, 2008
ChartItemEvent.CHANGE in conflict with IndexChangedEvent
Earlier this week I ran into a strange problem when the ChartItemEvent.CHANGE event is raised. It seems that the string behind the constant is 'change' and this happens to be the same as the string behind the IndexChangedEvent.CHANGE event. Probably programmed on monday morning :)
Fortunately there's a simple workaround:
Put a container around your 'problematic' charting component (for example a canvas) and attach a listener to the ChartItemEvent.CHANGE event to stop it from propagating.
<mx:Canvas id="canvas" creationComplete="canvasInit()">
<mx:PieChart id="pieChart" ... />
</mx:Canvas>
// Hack to prevent propagation of the ChartItemEvent.CHANGE as it is in conflict with IndexChangedEvent.CHANGE
private function canvasInit(): void
{
canvasInit.addEventListener(ChartItemEvent.CHANGE, chartItemEventChange, true, 0, true);
}
private function chartItemEventChange(event: Event): void
{
event.stopImmediatePropagation();
}
Fortunately there's a simple workaround:
Put a container around your 'problematic' charting component (for example a canvas) and attach a listener to the ChartItemEvent.CHANGE event to stop it from propagating.
<mx:Canvas id="canvas" creationComplete="canvasInit()">
<mx:PieChart id="pieChart" ... />
</mx:Canvas>
// Hack to prevent propagation of the ChartItemEvent.CHANGE as it is in conflict with IndexChangedEvent.CHANGE
private function canvasInit(): void
{
canvasInit.addEventListener(ChartItemEvent.CHANGE, chartItemEventChange, true, 0, true);
}
private function chartItemEventChange(event: Event): void
{
event.stopImmediatePropagation();
}
Tuesday, January 29, 2008
Is your PopupButton suffering from Alzheimer?
Recently I noticed that my PopupButton didn't want to popup anymore... Sometimes it worked and most of the time it didn't. The problem is related to a 'fix' Adobe did to get rid of a memory leak. The 'fix' may have fixed the memory leak but introduced serious trouble. Scott Melby seems to have found a workaround that works most of the time. More information on http://tech.groups.yahoo.com/group/flexcoders/message/99105. Let's hope this gets fixed soon because it's clearly a bad fix.
Thursday, January 24, 2008
How to use a percentage for maxWidth or maxHeight?
Recently I wanted to set the maxHeight of a component to a percentage. Sadly enough this isn't supported in Flex. There's however a very simple workaround that seems to work all the time: set the maxHeight or maxWidth in the resize event of its container:
<mx:Canvas
id="cnvsComponent"
resize="childComponent.maxHeight = cnvsComponent.height"
width="100%" height="100%">
<mx:Tree id="childComponent" />
</mx:Canvas>
<mx:Canvas
id="cnvsComponent"
resize="childComponent.maxHeight = cnvsComponent.height"
width="100%" height="100%">
<mx:Tree id="childComponent" />
</mx:Canvas>
Tuesday, January 22, 2008
Taming your combobox width
Recently I discovered that setting a combobox to width="100%" doesn't mean the combobox won't grow bigger than the width of its container. If the text cannot be completely displayed your combobox becomes wider than 100%. You can use the following construction to tame its width:
<mx:canvas id="cnvs" width="100%" resize="cb.width = cnvs.width">
<mx:combobox id="cb" text="this is a rather long combobox text" />
</mx:canvas>
Simply add a canvas around the combobox and explicitly set the width of the combobox to the width of the canvas through the resize event of the canvas. This solution works because the problematic behaviour only occurs when using a percentage width.
The same applies to the Label component (and probably some other components as well).
<mx:canvas id="cnvs" width="100%" resize="cb.width = cnvs.width">
<mx:combobox id="cb" text="this is a rather long combobox text" />
</mx:canvas>
Simply add a canvas around the combobox and explicitly set the width of the combobox to the width of the canvas through the resize event of the canvas. This solution works because the problematic behaviour only occurs when using a percentage width.
The same applies to the Label component (and probably some other components as well).
Friday, January 18, 2008
Trouble centering your popups ???
I had some trouble centering popups created through PopupManager. If you simply use 'this' as the parent display object then the popup is 'centered' according to the parent component specified (instead of to the complete stage). If you want to center your popup in the middle of your application screen you should specify 'Application.application.parentDocument'...
Monday, November 12, 2007
Is your TabNavigator showing wrong content?
I ran into a very strange problem: sometimes my tab navigator showed the content of a different tab than the selected tab... This happened when the tabs were VDividedBox containers instead of Canvas containers. Putting a Canvas container around the VDividedBox solved the akward problem. I hope it does for you as well.
Subscribe to:
Posts (Atom)
