Re: [flexcoders] Re: Reuse a LabelFunction

2010-04-19 Thread Angelo Anolin


Thank you Alex and Amy for clarification.

Angelo



From: Alex Harui aha...@adobe.com
To: flexcoders@yahoogroups.com flexcoders@yahoogroups.com
Sent: Fri, 16 April, 2010 22:51:20
Subject: Re: [flexcoders] Re: Reuse a LabelFunction

  
Amy is saying you could write your function like this:

private function labelFunctionTest( itm:Object, col:DataGridColumn) :String 
{
return df.format(itm[ col.dataField] );
}

Which is correct and probably the easiest way to go.  If you want to subclass 
you would do something like this:

 public class AngeloDataGridColum n extends DataGridColumn
 {
 public function AngeloDataGridColum n()
 {
 labelFunction = labelFunctionTest;
 }

 private function labelFunctionTest( item:Object, col:DataGridColumn) 
:String
 {
 return owner.document. df.format( item[dataField] );
 }
 }

By subclassing you don’t have to assign the labelFunctions to the columns that 
need them.

On 4/16/10 2:12 PM, Angelo Anolin angelo_anolin@ yahoo.com wrote:



 
 
   

Hi Alex,
 
Appreciate if you could show a little example.
 
Thanks.
 
Angelo



From:Alex Harui aha...@adobe. com
To: flexcod...@yahoogro ups.com flexcod...@yahoogro ups.com
Sent: Fri, 16 April, 2010 12:29:57
Subject: Re: [flexcoders] Re: Reuse a LabelFunction

  
If it were me, I would subclass DataGridColumn and add the labelfunction to 
the subclass.  Then it has the DGC’s context like dataField to work with.


On 4/16/10 7:40 AM, valdhor valdhorlists@ embarqmail. com wrote:



 
 
   

If it were me, I would use an item renderer.

--- In flexcod...@yahoogro ups.com mailto:flexcoders% 40yahoogroups. com 
mailto:flexcoders% 40yahoogroups. com  , Angelo Anolin angelo_anolin@ 
... wrote:

 Hi Amy,
 
 But as you can see in the function, I am specifying the Datafieldname 
 from the object which was passed.
 
 How can I make it more generic so that I can re-use it in other datagrid 
 columns?  I hope you could provide some samples. thanks.
 
 Angelo
 
 
 
 
  _ _ __
 From: Amy amyblankenship@ ...
 To: flexcod...@yahoogro ups.com mailto:flexcoders% 40yahoogroups. com 
 mailto:flexcoders% 40yahoogroups. com  
 Sent: Fri, 19 March, 2010 9:13:38
 Subject: [flexcoders] Re: Reuse a LabelFunction
 
 Â  
 
 
 --- In flexcod...@yahoogro ups.com, Angelo Anolin angelo_anolin@ ... 
 wrote:
 
  Hi FlexCoders,
  
  I have created a labelfunction which I use in my datagrid to format the 
  display value.
  
  mx:DateFormatter id=df formatString= DD/MM/ /
  
  And this is the AS function
  private function labelFunctionTest( itm:Object, col:DataGridColumn) 
  :String
  {
  Â Â Â  return df.format(itm. DataFieldNamefor Col1);
  }
  
  Is there a way so that I could reuse the same label function to other 
  datagrid columns?  As you can see from the script above, I am only 
  using the function to Col1 for the datagrid.  How would I be able to 
  specify the datafield if I am going to reuse the same with other 
  datagrid columns?
 
 That is what the DataGridColumn parameter is for. Look at its dataField 
 property.
 
 HTH;
 
 Amy


 
   



-- 
Alex Harui
Flex SDK Team
Adobe System, Inc.
http://blogs. adobe.com/ aharui
 
 


  

Re: [flexcoders] Re: Reuse a LabelFunction

2010-04-16 Thread Angelo Anolin
Hi Amy,

But as you can see in the function, I am specifying the Datafieldname from the 
object which was passed.

How can I make it more generic so that I can re-use it in other datagrid 
columns?  I hope you could provide some samples. thanks.

Angelo





From: Amy amyblankens...@bellsouth.net
To: flexcoders@yahoogroups.com
Sent: Fri, 19 March, 2010 9:13:38
Subject: [flexcoders] Re: Reuse a LabelFunction

  


--- In flexcod...@yahoogro ups.com, Angelo Anolin angelo_anolin@ ... wrote:

 Hi FlexCoders,
 
 I have created a labelfunction which I use in my datagrid to format the 
 display value.
 
 mx:DateFormatter id=df formatString= DD/MM/ /
 
 And this is the AS function
 private function labelFunctionTest( itm:Object, col:DataGridColumn) :String
 {
     return df.format(itm. DataFieldNamefor Col1);
 }
 
 Is there a way so that I could reuse the same label function to other 
 datagrid columns?  As you can see from the script above, I am only using the 
 function to Col1 for the datagrid.  How would I be able to specify the 
 datafield if I am going to reuse the same with other datagrid columns?

That is what the DataGridColumn parameter is for. Look at its dataField 
property.

HTH;

Amy





  

[flexcoders] Re: Reuse a LabelFunction

2010-04-16 Thread valdhor
If it were me, I would use an item renderer.

--- In flexcoders@yahoogroups.com, Angelo Anolin angelo_ano...@... wrote:

 Hi Amy,
 
 But as you can see in the function, I am specifying the Datafieldname from 
 the object which was passed.
 
 How can I make it more generic so that I can re-use it in other datagrid 
 columns?  I hope you could provide some samples. thanks.
 
 Angelo
 
 
 
 
 
 From: Amy amyblankens...@...
 To: flexcoders@yahoogroups.com
 Sent: Fri, 19 March, 2010 9:13:38
 Subject: [flexcoders] Re: Reuse a LabelFunction
 
   
 
 
 --- In flexcod...@yahoogro ups.com, Angelo Anolin angelo_anolin@ ... wrote:
 
  Hi FlexCoders,
  
  I have created a labelfunction which I use in my datagrid to format the 
  display value.
  
  mx:DateFormatter id=df formatString= DD/MM/ /
  
  And this is the AS function
  private function labelFunctionTest( itm:Object, col:DataGridColumn) :String
  {
      return df.format(itm. DataFieldNamefor Col1);
  }
  
  Is there a way so that I could reuse the same label function to other 
  datagrid columns?  As you can see from the script above, I am only using 
  the function to Col1 for the datagrid.  How would I be able to specify the 
  datafield if I am going to reuse the same with other datagrid columns?
 
 That is what the DataGridColumn parameter is for. Look at its dataField 
 property.
 
 HTH;
 
 Amy





Re: [flexcoders] Re: Reuse a LabelFunction

2010-04-16 Thread Alex Harui
If it were me, I would subclass DataGridColumn and add the labelfunction to the 
subclass.  Then it has the DGC’s context like dataField to work with.


On 4/16/10 7:40 AM, valdhor valdhorli...@embarqmail.com wrote:






If it were me, I would use an item renderer.

--- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com , 
Angelo Anolin angelo_ano...@... wrote:

 Hi Amy,

 But as you can see in the function, I am specifying the Datafieldname from 
 the object which was passed.

 How can I make it more generic so that I can re-use it in other datagrid 
 columns?  I hope you could provide some samples. thanks.

 Angelo




 
 From: Amy amyblankens...@...
 To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com
 Sent: Fri, 19 March, 2010 9:13:38
 Subject: [flexcoders] Re: Reuse a LabelFunction

 Â


 --- In flexcod...@yahoogro ups.com, Angelo Anolin angelo_anolin@ ... wrote:
 
  Hi FlexCoders,
 
  I have created a labelfunction which I use in my datagrid to format the 
  display value.
 
  mx:DateFormatter id=df formatString= DD/MM/ /
 
  And this is the AS function
  private function labelFunctionTest( itm:Object, col:DataGridColumn) :String
  {
  Â Â Â  return df.format(itm. DataFieldNamefor Col1);
  }
 
  Is there a way so that I could reuse the same label function to other 
  datagrid columns?  As you can see from the script above, I am only using 
  the function to Col1 for the datagrid.  How would I be able to specify the 
  datafield if I am going to reuse the same with other datagrid columns?

 That is what the DataGridColumn parameter is for. Look at its dataField 
 property.

 HTH;

 Amy







--
Alex Harui
Flex SDK Team
Adobe System, Inc.
http://blogs.adobe.com/aharui


Re: [flexcoders] Re: Reuse a LabelFunction

2010-04-16 Thread Angelo Anolin
Hi Alex,

Appreciate if you could show a little example.

Thanks.

Angelo





From: Alex Harui aha...@adobe.com
To: flexcoders@yahoogroups.com flexcoders@yahoogroups.com
Sent: Fri, 16 April, 2010 12:29:57
Subject: Re: [flexcoders] Re: Reuse a LabelFunction

  
If it were me, I would subclass DataGridColumn and add the labelfunction to the 
subclass.  Then it has the DGC’s context like dataField to work with.


On 4/16/10 7:40 AM, valdhor valdhorlists@ embarqmail. com wrote:



 
 
   

If it were me, I would use an item renderer.

--- In flexcod...@yahoogro ups.com mailto:flexcoders% 40yahoogroups. com , 
Angelo Anolin angelo_anolin@ ... wrote:

 Hi Amy,
 
 But as you can see in the function, I am specifying the Datafieldname from 
 the object which was passed.
 
 How can I make it more generic so that I can re-use it in other datagrid 
 columns?  I hope you could provide some samples. thanks.
 
 Angelo
 
 
 
 
  _ _ __
 From: Amy amyblankenship@ ...
 To: flexcod...@yahoogro ups.com mailto:flexcoders% 40yahoogroups. com 
 Sent: Fri, 19 March, 2010 9:13:38
 Subject: [flexcoders] Re: Reuse a LabelFunction
 
 Â  
 
 
 --- In flexcod...@yahoogro ups.com, Angelo Anolin angelo_anolin@ ... wrote:
 
  Hi FlexCoders,
  
  I have created a labelfunction which I use in my datagrid to format the 
  display value.
  
  mx:DateFormatter id=df formatString= DD/MM/ /
  
  And this is the AS function
  private function labelFunctionTest( itm:Object, col:DataGridColumn) :String
  {
  Â Â Â  return df.format(itm. DataFieldNamefor Col1);
  }
  
  Is there a way so that I could reuse the same label function to other 
  datagrid columns?  As you can see from the script above, I am only using 
  the function to Col1 for the datagrid.  How would I be able to specify 
  the datafield if I am going to reuse the same with other datagrid columns?
 
 That is what the DataGridColumn parameter is for. Look at its dataField 
 property.
 
 HTH;
 
 Amy


 
   



-- 
Alex Harui
Flex SDK Team
Adobe System, Inc.
http://blogs. adobe.com/ aharui




  

[flexcoders] Re: Reuse a LabelFunction

2010-04-16 Thread Amy


--- In flexcoders@yahoogroups.com, Angelo Anolin angelo_ano...@... wrote:

 Hi Amy,
 
 But as you can see in the function, I am specifying the Datafieldname from 
 the object which was passed.
 
 How can I make it more generic so that I can re-use it in other datagrid 
 columns?  I hope you could provide some samples. thanks.

By looking at the column value that gets passed into your function and seeing 
what data field it's talking about.



Re: [flexcoders] Re: Reuse a LabelFunction

2010-04-16 Thread Alex Harui
Amy is saying you could write your function like this:

private function labelFunctionTest( itm:Object, col:DataGridColumn) :String
{
return df.format(itm[col.dataField]);
}

Which is correct and probably the easiest way to go.  If you want to subclass 
you would do something like this:

 public class AngeloDataGridColumn extends DataGridColumn
 {
 public function AngeloDataGridColumn()
 {
 labelFunction = labelFunctionTest;
 }

 private function labelFunctionTest(item:Object, col:DataGridColumn):String
 {
 return owner.document.df.format(item[dataField]);
 }
 }

By subclassing you don’t have to assign the labelFunctions to the columns that 
need them.

On 4/16/10 2:12 PM, Angelo Anolin angelo_ano...@yahoo.com wrote:






Hi Alex,

Appreciate if you could show a little example.

Thanks.

Angelo


From: Alex Harui aha...@adobe.com
To: flexcoders@yahoogroups.com flexcoders@yahoogroups.com
Sent: Fri, 16 April, 2010 12:29:57
Subject: Re: [flexcoders] Re: Reuse a LabelFunction


If it were me, I would subclass DataGridColumn and add the labelfunction to the 
subclass.  Then it has the DGC’s context like dataField to work with.


On 4/16/10 7:40 AM, valdhor valdhorlists@ embarqmail. com wrote:






If it were me, I would use an item renderer.

--- In flexcod...@yahoogro ups.com mailto:flexcoders% 40yahoogroups. com 
mailto:flexcoders%40yahoogroups.com  , Angelo Anolin angelo_anolin@ ... 
wrote:

 Hi Amy,

 But as you can see in the function, I am specifying the Datafieldname from 
 the object which was passed.

 How can I make it more generic so that I can re-use it in other datagrid 
 columns?  I hope you could provide some samples. thanks.

 Angelo




  _ _ __
 From: Amy amyblankenship@ ...
 To: flexcod...@yahoogro ups.com mailto:flexcoders% 40yahoogroups. com 
 mailto:flexcoders%40yahoogroups.com 
 Sent: Fri, 19 March, 2010 9:13:38
 Subject: [flexcoders] Re: Reuse a LabelFunction

 Â


 --- In flexcod...@yahoogro ups.com, Angelo Anolin angelo_anolin@ ... wrote:
 
  Hi FlexCoders,
 
  I have created a labelfunction which I use in my datagrid to format the 
  display value.
 
  mx:DateFormatter id=df formatString= DD/MM/ /
 
  And this is the AS function
  private function labelFunctionTest( itm:Object, col:DataGridColumn) :String
  {
  Â Â Â  return df.format(itm. DataFieldNamefor Col1);
  }
 
  Is there a way so that I could reuse the same label function to other 
  datagrid columns?  As you can see from the script above, I am only using 
  the function to Col1 for the datagrid.  How would I be able to specify the 
  datafield if I am going to reuse the same with other datagrid columns?

 That is what the DataGridColumn parameter is for. Look at its dataField 
 property.

 HTH;

 Amy







--
Alex Harui
Flex SDK Team
Adobe System, Inc.
http://blogs.adobe.com/aharui


[flexcoders] Re: Reuse a LabelFunction

2010-03-19 Thread Amy


--- In flexcoders@yahoogroups.com, Angelo Anolin angelo_ano...@... wrote:

 Hi FlexCoders,
 
 I have created a labelfunction which I use in my datagrid to format the 
 display value.
 
 mx:DateFormatter id=df formatString=DD/MM/ /
 
 And this is the AS function
 private function labelFunctionTest(itm:Object, col:DataGridColumn) :String
 {
     return df.format(itm.DataFieldNameforCol1);
 }
 
 Is there a way so that I could reuse the same label function to other 
 datagrid columns?  As you can see from the script above, I am only using the 
 function to Col1 for the datagrid.  How would I be able to specify the 
 datafield if I am going to reuse the same with other datagrid columns?

That is what the DataGridColumn parameter is for. Look at its dataField 
property.

HTH;

Amy



[flexcoders] Re: Reuse a LabelFunction

2010-03-18 Thread valdhor
You could write the Item Renderer as an MXML component or an
ActionScript class.

I have created a sample of both types that do the same thing. Sometimes
it easier to do it in MXML; Sometimes AS is the best way. With this
trivial example, both are about the same. Pick whichever way you like
the best.

DateRendererAS.as
package ItemRenderers
{
 import mx.controls.*;
 import mx.controls.dataGridClasses.DataGridListData;
 import mx.formatters.DateFormatter;

 public class DateRendererAS extends Label
 {
 private var myDateFormatter:DateFormatter = new DateFormatter();

 public function DateRendererAS()
 {
 super();
 myDateFormatter.formatString = DD/MMM/;
 }

 override public function set data(value:Object):void
 {
 if(value != null)
 {
 super.data = value;
 text =
myDateFormatter.format(value[DataGridListData(listData).dataField]);
 }
 }
 }
}

DateRendererMXML.mxml
?xml version=1.0 encoding=utf-8?
mx:Label xmlns:mx=http://www.adobe.com/2006/mxml;
 mx:Script
 ![CDATA[
 import mx.controls.dataGridClasses.DataGridListData;

 override public function set data(value:Object):void
 {
 if(value != null)
 {
 super.data = value;
 text =
myDateFormatter.format(value[DataGridListData(listData).dataField]);
 }
 }
 ]]
 /mx:Script
 mx:DateFormatter id=myDateFormatter formatString=DD/MMM//
/mx:Label


And here is an application to try them out with (Change the itemRenderer
to DateRendererAS to try the AS version)
?xml version=1.0 encoding=utf-8?
mx:Application xmlns:mx=http://www.adobe.com/2006/mxml;
layout=vertical
 mx:Script
 ![CDATA[
 private var dp:Array = [
 {symbol: ADBE, name: Adobe Systems Inc.,
dateIncorporated: 3/1/50},
 {symbol: MACR, name: Macromedia Inc.,
dateIncorporated: 1/1/84},
 {symbol: MSFT, name: Microsoft Corp.,
dateIncorporated: 11/24/71},
 {symbol: IBM, name: IBM Corp., dateIncorporated:
9/14/63}
 ];
 ]]
 /mx:Script
 mx:DataGrid id=dg initialize=dg.dataProvider = dp
verticalAlign=middle
 mx:columns
 mx:DataGridColumn headerText=Name dataField=name
width=140/
 mx:DataGridColumn headerText=Symbol dataField=symbol
width=60 /
 mx:DataGridColumn headerText=Date
dataField=dateIncorporated width=100
itemRenderer=ItemRenderers.DateRendererMXML /
 /mx:columns
 /mx:DataGrid
/mx:Application



--- In flexcoders@yahoogroups.com, Angelo Anolin angelo_ano...@...
wrote:

 I do know a bit of using itemrenderer.. Inline that is..

 if you could post some example, I'd greatly appreciate it.

 would the itemrenderer be an as file or would it be inline as well?

 Thanks.

 Angelo



 
 From: valdhor valdhorli...@...
 To: flexcoders@yahoogroups.com
 Sent: Wed, 17 March, 2010 14:41:19
 Subject: [flexcoders] Re: Reuse a LabelFunction


 Use an itemRenderer instead.

 If you need help creating one, let me know.

 --- In flexcod...@yahoogro ups.com, Angelo Anolin angelo_anolin@ ...
wrote:
 
  Hi FlexCoders,
 
  I have created a labelfunction which I use in my datagrid to format
the display value.
 
  mx:DateFormatter id=df formatString= DD/MM/ /
 
  And this is the AS function
  private function labelFunctionTest( itm:Object, col:DataGridColumn)
:String
  {
  return df.format(itm. DataFieldNamefor Col1);
  }
 
  Is there a way so that I could reuse the same label function to
other datagrid columns?  As you can see from the script above, I am only
using the function to Col1 for the datagrid.  How would I be able to
specify the datafield if I am going to reuse the same with other
datagrid columns?
 
  Thanks.
 




[flexcoders] Re: Reuse a LabelFunction

2010-03-17 Thread valdhor
Use an itemRenderer instead.

If you need help creating one, let me know.

--- In flexcoders@yahoogroups.com, Angelo Anolin angelo_ano...@... wrote:

 Hi FlexCoders,
 
 I have created a labelfunction which I use in my datagrid to format the 
 display value.
 
 mx:DateFormatter id=df formatString=DD/MM/ /
 
 And this is the AS function
 private function labelFunctionTest(itm:Object, col:DataGridColumn) :String
 {
     return df.format(itm.DataFieldNameforCol1);
 }
 
 Is there a way so that I could reuse the same label function to other 
 datagrid columns?  As you can see from the script above, I am only using the 
 function to Col1 for the datagrid.  How would I be able to specify the 
 datafield if I am going to reuse the same with other datagrid columns?
 
 Thanks.





Re: [flexcoders] Re: Reuse a LabelFunction

2010-03-17 Thread Alex Harui
Should be df.format(item[col.dataField])


On 3/17/10 1:41 PM, valdhor valdhorli...@embarqmail.com wrote:






Use an itemRenderer instead.

If you need help creating one, let me know.

--- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com , 
Angelo Anolin angelo_ano...@... wrote:

 Hi FlexCoders,

 I have created a labelfunction which I use in my datagrid to format the 
 display value.

 mx:DateFormatter id=df formatString=DD/MM/ /

 And this is the AS function
 private function labelFunctionTest(itm:Object, col:DataGridColumn) :String
 {
 return df.format(itm.DataFieldNameforCol1);
 }

 Is there a way so that I could reuse the same label function to other 
 datagrid columns?  As you can see from the script above, I am only using the 
 function to Col1 for the datagrid.  How would I be able to specify the 
 datafield if I am going to reuse the same with other datagrid columns?

 Thanks.







--
Alex Harui
Flex SDK Team
Adobe System, Inc.
http://blogs.adobe.com/aharui


Re: [flexcoders] Re: Reuse a LabelFunction

2010-03-17 Thread Angelo Anolin
Ho would I be able to specify other dataField based from your example?

Say in my datagrid, col1's datafield is COL1 and col2 is COL2.

Using the label function, I need to fully qualify the datafield name like:

df.format(item[col.COL1])

which in turn I could only use for COL1.

Since I have some datagrid where the same date formatting can be used, then 
perhaps re-using the same label function would be of good help.

Thanks.




From: Alex Harui aha...@adobe.com
To: flexcoders@yahoogroups.com flexcoders@yahoogroups.com
Sent: Wed, 17 March, 2010 19:13:26
Subject: Re: [flexcoders] Re: Reuse a LabelFunction

  
Should be df.format(item[ col.dataField] )


On 3/17/10 1:41 PM, valdhor valdhorlists@ embarqmail. com wrote:



 
 
   

Use an itemRenderer instead.

If you need help creating one, let me know.

--- In flexcod...@yahoogro ups.com mailto:flexcoders% 40yahoogroups. com , 
Angelo Anolin angelo_anolin@ ... wrote:

 Hi FlexCoders,
 
 I have created a labelfunction which I use in my datagrid to format the 
 display value.
 
 mx:DateFormatter id=df formatString=DD/MM/ /
 
 And this is the AS function
 private function labelFunctionTest( itm:Object, col:DataGridColumn) :String
 {
 return df.format(itm. DataFieldNamefor Col1);
 }
 
 Is there a way so that I could reuse the same label function to other 
 datagrid columns?  As you can see from the script above, I am only using 
 the function to Col1 for the datagrid.  How would I be able to specify the 
 datafield if I am going to reuse the same with other datagrid columns?
 
 Thanks.


 
   



-- 
Alex Harui
Flex SDK Team
Adobe System, Inc.
http://blogs. adobe.com/ aharui
 
 


  

Re: [flexcoders] Re: Reuse a LabelFunction

2010-03-17 Thread Angelo Anolin
I do know a bit of using itemrenderer.. Inline that is.. 

if you could post some example, I'd greatly appreciate it.

would the itemrenderer be an as file or would it be inline as well?

Thanks.

Angelo




From: valdhor valdhorli...@embarqmail.com
To: flexcoders@yahoogroups.com
Sent: Wed, 17 March, 2010 14:41:19
Subject: [flexcoders] Re: Reuse a LabelFunction

  
Use an itemRenderer instead.

If you need help creating one, let me know.

--- In flexcod...@yahoogro ups.com, Angelo Anolin angelo_anolin@ ... wrote:

 Hi FlexCoders,
 
 I have created a labelfunction which I use in my datagrid to format the 
 display value.
 
 mx:DateFormatter id=df formatString= DD/MM/ /
 
 And this is the AS function
 private function labelFunctionTest( itm:Object, col:DataGridColumn) :String
 {
 return df.format(itm. DataFieldNamefor Col1);
 }
 
 Is there a way so that I could reuse the same label function to other 
 datagrid columns?  As you can see from the script above, I am only using the 
 function to Col1 for the datagrid.  How would I be able to specify the 
 datafield if I am going to reuse the same with other datagrid columns?
 
 Thanks.