Monthly Archives: February 2005

DataGrid CellRenderer V2 Error


There is an error in the V2 DataGrid CellRenderer that makes using components within the dataGrid problematic. Here is the fix.&

In Class “mx.controls.gridclasses.DataGridRow” line 165:


cell._y = (__height-cell._height)/2;

Replace this line with:

if( cell.__height == undefined ){
cell._y = (__height-cell._height)/2;
}else{
cell._y = (__height-cell.__height)/2;
}

The problem was that the cell _y coordinate was based on _height not __height for components. If you added a ComboBox or NumericStepper into a Cell, they would resize incorrectly. The ComboBox would be ok until you opened it and then resized a column. Since the _height of the cell now contains the dropdown list, the _y of the cell is thrown off shooting the cell up aboout 50px. Using __height resolves the issue, but makes it essential to defined a getPreferredHeight function in your cell renderer class.

This makes writing cell renderers for DataGrid much easier allowing just about any component to be inserted, or better many controls in a form.

Cheers and Happy CellRenderering!

Ted ;)

Boolean Conversion Problems


I have witnessed many people (including myself) make mistakes with Boolean Conversion. Here is a small example to explore the problem.&

The following example highlights some of the problems people encounter with Boolean Conversion. Although the differences are subtle, they can wreck havoc in your application if you do not understand the results.

Example:
trace( ‘Boolean( 0 ) == ‘ + Boolean( 0 ) )
trace( ‘Boolean( 1 ) == ‘ + Boolean( 1 ) )
trace( ‘Boolean( “0” ) == ‘ + Boolean( ‘0’ ) )
trace( ‘Boolean( “1” ) == ‘ + Boolean( ‘1’ ) )
trace( ‘Boolean( “true” ) == ‘ + Boolean( ‘true’ ) )
trace( ‘Boolean( “false” ) == ‘ + Boolean( ‘false’ ) )
trace( ‘Boolean( “Donut” ) == ‘ + Boolean( ‘Donut’ ) )
trace( ‘Boolean( “” ) == ‘ + Boolean( ” ) )
trace( ‘Boolean( undefined ) == ‘ + Boolean( undefined ) )
trace( ‘Boolean( Null ) == ‘ + Boolean( Null ) )
trace( ‘Boolean( true ) == ‘ + Boolean( true ) )
trace( ‘Boolean( false ) == ‘ + Boolean( false ) )
myBoolTrue = new Boolean( true )
trace( ‘Boolean( myBoolTrue ) == ‘ + Boolean( myBoolTrue ) )
myBoolFalse = new Boolean( false )
trace( ‘Boolean( myBoolFalse ) == ‘ + Boolean( myBoolFalse ) )

This will result in the following output:

Boolean( 0 ) == false
Boolean( 1 ) == true
Boolean( “0” ) == true
Boolean( “1” ) == true
Boolean( “true” ) == true
Boolean( “false” ) == true
Boolean( “Donut” ) == true
Boolean( “” ) == false
Boolean( undefined ) == false
Boolean( Null ) == false
Boolean( true ) == true
Boolean( false ) == false
Boolean( myBoolTrue ) == true
Boolean( myBoolFalse ) == true

The String based results are often the most puzzling as one would expect that strings might be interpreted. If a String is present, it results in true, if empty false. Also objects are tested if they exist, not if the object evaluates to a Boolean. In the example I pass in a Boolean Object and since it exists, it is true, even when the value is internally false.

The real problems start when you realize that you get different results when you use the if() statement and expect Boolean conversion. For example:

if( “” ){
trace(‘true’)
}else{
trace(‘false’)
}
//true

//But…

if( Boolean( “” ) ){
trace(‘true’)
}else{
trace(‘false’)
}
//false

Be careful with your Boolean expectations, errors can seep into your application if your not careful.

Cheers,

Ted ;)

Gradient PanelBase with AS


As a follow-up to Dynamic Gradients in AS, here is the PanelBase. The PanelBase is a decoration control for creating an Panels, HBox, VBox, Dialogs, Windows, etc.

The version here supports:

1. Dynamically rounded corners via a property.
2. 12 Gradient types including none, vertical, angle, light, and dark.
3. PanelBase is resizeable via setSize methods.
3. Dynamically Color the gradients with RGB values.

The trick is using a mask with drawing API contents and a clip of 12 predefined gradients. Also you must hide the mask clip from V2 by blocking path lookups to the clips. V2 focusManager uses the drawing API to render glows on selected controls, when the glow is fired, clear() is called eliminating all drawing API content except the glow. You can avoid this by storing a reference to the mask in your class and having data that blocks access to the clip itself by name. FocusManager cannot reach in and overwrite your Drawing API layout.

Example:

Cheers,

Ted ;)

The Death of an IPOD


My wife received a 30GB IPOD for Christmas 2003. This month she complained that it crashed constantly and wouldn’t sync. Here is how to defend yourself from IPOD defects, TEST, TEST, TEST.&

I encourage any IPOD owner to test their entire disks for bad sectors while your IPOD is still under warranty. In my wifes case, the bad sector was their the entire time, she just had not reached that capacity until recently. Here is how to test your IPOD:

1. Reboot your IPOD by holding down “MENU” and “PLAY/PAUSE”.

2. When you see the APPLE LOGO, Hold down these keys until the logo disappears:
“|<<" – Back Button
“>>|” – Next Button
“Wheel Button” – Center button on the Wheel

3. Suddenly you will hear a “Defender Fire” like sound and the APPLE will be backwards. You have entered the Apple Diagnostic Toolset

4. Using the Arrow keys scroll down to Option “O . HDD SCAN”

5. Press the “Wheel Button” to start the HDD SCAN and wait 4-10 hours for it to complete. The test will finish, it just takes time considering the size of the disk.

At the end if everything passed you will get a “DISK PASSED” or in our case you will get a “DISK READ FAIL – 0x00000007″.

This will exhaustively test your disk for read and write capability. It will not affect the data on the disk, but it will assure you there are no bad sectors lurking on your IPOD ready for you to find when you have filled it up.

We are still waiting on a judgment from APPLE as to repair, if they judge it is out of warranty, we will be forced to buy a new IPOD. It is interesting how the investment in music in Itunes format will lock you into hardware. Standing in the Apple store I was focusing on the bite in the apple rather than the whole of their brand. It is such a cruel irony, you love using this gadgetry, yet when it dies you really feel a loss. Apple has a choice, they can recognize that the sector defect existed when we purchased the IPOD or say we are out of warranty, tough luck.

Do not let this happen to you. Run the diagnostics on your IPOD to check for bad sectors. If you get a failure and your IPOD is under 1 year old, take it into APPLE, you will get a free IPOD on the house as they do not repair them, they replace them.

Cheers,

Ted ;)

Dynamic Gradients via AS


There is a great trick for coloring gradients using Color.setTransform. I am working on a set of Container components for FLOW 2 and needed to color gradients dynamically for panels, dialogs, and windows.&

This is probably old school for some but the transform object lets you color objects with much more precision than setRGB.

1. Create a gradient ranging from Black to White.

2. Make the gradient a MovieClip and give it an instance name “myGradient”

3. Add the following AS to the timeline:

// create a color targeting myGradient
myGradientColor = new Color( myGradient )

// use setTransform to make the gradient slightly red
myGradientColor.setTransform( {ra:100, ga:70 , ba:70 } )

Here is a working SWF version with some controls for editing the gradient.

Cheers,

Ted Patrick

_level0 as a Class Instance


There is an interesting bit of code for making the root of your movie a class instance. This eliminates an extra nested movieclip and makes things much cleaner. Plus it works with AS2.&

This essentially makes the movie a class instance and all objects/properties/movieclips are within the class instance. Notice the lack of an import statement and that there are zero clips in the library.

Source Example

//modify the inheiritance chain to point to a Class
this.__proto__ = Application['prototype']

//call the Class constuctor targeting the root or this
_global.Application.apply( this , [] )

Anytime you want to call a method you can go any of the following:

this.myMethod()
_level0.myMethod()
_root.myMethod()

Now if we could only find a way to create forms and views at runtime without predefined library movieClips. Looks like a job for FLOW!

Cheers,

Ted ;)