<charlie griefer>

*tap*tap*tap* is this thing on?

flex images: visible property funkiness in itemRenderer

may 13, 2008 at 9:56pm in flex

in the flex app that i'm currently working on, i have a DataGrid that uses an itemRenderer to display an image. the image is a 'delete' button that allows the user to delete the item. fairly straightforward, and the code below was working fine...

  1. <mx:DataGridColumn width="24" sortable="false" paddingLeft="4" paddingRight="4" headerText="">
  2. <mx:itemRenderer>
  3. <mx:Component>
  4. <mx:Image source="assets/icon_delete.png" horizontalAlign="center" height="17" width="17" click="parentDocument.confirmDelete(event);" />
  5. </mx:Component>
  6. </mx:itemRenderer>
  7. </mx:DataGridColumn>

... until the customer called and said that the user should not be allowed to delete a record if that record meets a particular condition. ok. i think i can do that. i made some modifications and now had the following code:

  1. <mx:DataGridColumn width="24" sortable="false" paddingLeft="4" paddingRight="4" headerText="" dataField="CAN_DELETE">
  2. <mx:itemRenderer>
  3. <mx:Component>
  4. <mx:Image source="assets/icon_delete.png" horizontalAlign="center" height="17" width="17" click="parentDocument.confirmDelete(event);" visible="{data.CAN_DELETE == 1}" />
  5. </mx:Component>
  6. </mx:itemRenderer>
  7. </mx:DataGridColumn>

i added a "dataField" property to the DataGridColumn, and added a "visible" property to the image itself, bound to the value of CAN_DELETE. recompiled, and still saw that every record displayed the delete image. i wondered if my logic, as simple as it was, might have been off. just for kicks and giggles, i hard coded the value 'false' into the "visible" property of the image. still, it displayed for all records. now this was odd.

one of the big perks of my current job is that i get to work with tariq ahmed, flex guru and all around good guy. while he wasn't able to offer up a reason as to why this behavior was happening, he suggested throwing the image into an <mx:HBox> component. new code:

  1. <mx:DataGridColumn width="24" sortable="false" paddingLeft="4" paddingRight="4" headerText="" dataField="CAN_DELETE">
  2. <mx:itemRenderer>
  3. <mx:Component>
  4. <mx:HBox>
  5. <mx:Image source="assets/icon_delete.png" horizontalAlign="center" height="17" width="17" click="parentDocument.confirmDelete(event);" visible="{data.CAN_DELETE == 1}" />
  6. </mx:HBox>
  7. </mx:Component>
  8. </mx:itemRenderer>
  9. </mx:DataGridColumn>

you'll notice the only change is the addition of the <mx:HBox> around the <mx:Image>. for whatever reason, that worked perfectly. i don't pretend to know why, but i'm curious as heck. if you've got any ideas, please feel free to comment and enlighten me.

mxml is xml (duh?)

april 23, 2008 at 4:04pm in flex, flex for CF'ers

just a quickie today, something that i came across while playing around with flex. it could very well be a "duh, charlie" observation, but i think it bears mentioning.

flex makes it very easy to bind elements to other elements or objects. what this means is that a datagrid, for example, can be populated by the contents of an ArrayCollection (for CF'ers, think of an ArrayCollection as an array of structures). the first step is to declare the variable as bindable in your <mx:Script> block:

  1. [Bindable]
  2. private var myArray:ArrayCollection;

your DataGrid would then be declared as follows:

  1. <mx:DataGrid dataProvider="{myArray}" id="myDataGrid">

the curly braces around the value of the dataProvider attribute indicates that it's a bindable variable. all pretty straightforward. but there are other ways to use bind variables to influence the behavior of an element.

flex: Objects are like structures. kinda. (part ii)

april 18, 2008 at 1:34pm in ColdFusion, flex, flex for CF'ers

last night i started documenting my journey of learning flex, focusing on my use of the built-in Object datatype and some issues that i faced in that respect.

there was one other aspect of this that i meant to touch on. to recap, i was passing a single Object to a coldfusion CFC method. in my little coldfusion brain, i thought of this as being not unlike a structure. so, i expected the method to receive a single argument much like a struct with multiple keys.

let's say my actionscript function looked like this:

  1. var args:Object = new Object();
  2. args.stateCode = "CA";
  3. args.zipCode = "94583";
  4. args.territory = 3;
  5. // call the remote object method
  6. ro_Customers.getFilteredCustomers(args);

i created an Object, populated it with 3 variables (keys), and passed it as an argument to the getFilteredCustomers() method in my remote object (CFC). originally, my CFC looked like this:

  1. <cffunction name="getFilteredCustomers" returntype="query" access="remote">
  2. <cfargument name="filterCriteria" type="struct" required="true" />
  3. ...

i assumed that my args Object would be able to be referenced as a structure in the CFC. it's a single variable with key/value pairs just like a struct. but when i tried to reference #arguments.filterCriteria.stateCode# i found that the variable didn't exist.

what actually happens is that the CFC treats each value in the Object as its own argument. think argumentCollection instead of struct.

the correct code for the CFC's arguments is:

  1. <cffunction name="getFilteredCustomers" returntype="query" access="remote">
  2. <cfargument name="stateCode" type="string" required="false" />
  3. <cfargument name="zipCode" type="string" required="false" />
  4. <cfargument name="territory" type="number" required="false" />
  5. ...

aside from explicitly declaring each value in the Object, i set the 'required' attribute to false because in this case, not all of the values may be present in the Object. a user might choose to search only on stateCode, or only on zipCode, etc.

flex: Objects are like structures. kinda.

april 18, 2008 at 2:52am in ColdFusion, flex, flex for CF'ers

over the past few months i've been lucky enough to have the opportunity to start playing around with flex at work. overall it's been a pretty good experience. i think flex itself is a very cool technology, and flexbuilder absolutely ROCKS as an IDE. of course, there have been hurdles. some i was able to overcome pretty easily, and some left scars. i figured i'd post some of them here and hopefully save some other flex n00bs the hassle of figuring things out the hard way.

the application that i'm currently working on is fairly straightforward. let's call it a user manager. i present a couple of comboboxes that let the user filter by certain criteria (state, zipcode, etc) and populate a datagrid with the list of users that were returned.

i chose to pass these values in a single object. in coldfusion, this single object would be a structure. flex, or more appropriately, actionscript, has a comparable datatype, simply called Object. an Object would be created as follows:

  1. var args:Object = new Object();
  2. args.stateCode = "CA";
  3. args.zipCode = "94583";
  4. args.territory = 3;

fairly straightforward when compared to a coldfusion structure:

  1. <cfset args = structNew() />
  2. <cfset args.stateCode = "CA" />
  3. <cfset args.zipCode = "94583" />
  4. <cfset args.territory = 3 />

mike potter == santa?

december 20, 2007 at 8:58pm in flex

santa (as channeled by mike potter) arrived a bit early at the griefer household this year.

i just got home from work to find a box from amazon waiting on the doorstep.  it was the flex 2 book by chafic kazoun and joey lott, with the following note:

Merry Christmas from the Adobe Flex Team!  Thanks for your interest in Flex.
Add your Flex app to the Flex Showcase at http://flex.org/

From: Mike Potter, Flex Team

i'd heard of this happening to others, but never thought it would happen to me (which yes, i do recognize sounds like the opening to a penthouse letter).

i'll actually be donating this to the bay area cfug to be used as a raffle giveway during the next meeting.  turns out i already had this particular book.  not sure if i forgot to move it to the 'purchased' items on my wishlist or not (it's there now... but that's either because i'd already done it, or because mike bought me the book... likely the latter).  i figure by donating it to the CFUG, it'll still be going to a good cause.  if you're going to be in the bay area for the next meeting (jan 21, 6:30 pm) stop by.  the topic is flex and AIR (ted patrick will be presenting), so it's somewhat appropriate, i guess :)

in any event, the thought and effort is very much appreciated.  thanks to mike and the entire flex team.  merry christmas back atcha!

this one time... at flex camp...

july 23, 2007 at 1:56pm in flex, conferences

it was all very last minute... but i managed to get myself on the attendee list for flex camp this friday (27 july) up in san fran.

driving up from redlands with the family and plan to make a weekend out of it. flex camp on friday... saturday and sunday looking at potential house rentals in anticipation of the move in september. we have one appointment set up for a house in san ramon (which is where the new job is), possibly one in castro valley (if still available), and one in hayward that looks somewhat intriguing.



 
© 1999-2008, charlie griefer - design based on *Limelight* by www.mitchinson.net
blogCFC was created by raymond camden. this blog is running version 5.9.002.

CSS | XHTML