Re: [flexcoders] function binding toString !! Additional information

2007-12-29 Thread Kevin
1st; when i use function biding (textInput  
text={myInstance.toString()}/) , function binding works fine




are you sure about that?  I could be wrong, but I would guess that if  
you add a button under the TextInput tag your TextInput text value  
will not update as expected on the button click.


mx:Button label=Test click=myInstance.someProperty = 'testing'; /

(If in fact it does update for you, I would love to see your example  
code since it's possible there is an aspect of binding that I am  
missing.)


HOWEVER, the problem you are having with the item renderer is  
somewhat related, but different, problem.  Item renderers use 'data'   
as generic object to hold the data passed to the item render.  That  
object itself is bindable AND if the entire data object changes the  
functions and properties will update.  However, changes to the  
underlying properties or functions will not be detected without  
setting up binding a little more explicitly.  (Usually you don't get  
compiler warnings, but it you run in debug mode you should get run  
time messages in the console)  My solution to this is to explicitly  
bind the data property to an internal property of the item renderer  
using MXML.  When I do this the binding works correctly.


In my item renderer...

mx:Script
![CDATA[
[Bindable]
private var myInternalData:MyCustomClass;   

]]
/mx:Script
mx:Binding source=(data as MyCustomClass) source=myInternalData /
mx:Label text={myInternalData.myFunction()} /

Hopefully that helps your item renderer problem.

You are correct.  Functions can be bound BUT I think what Frederico  
was pointing out is that there are some important things to  
understand when binding with functions (which are stated in the  
document that you referenced.)  It is not as easy as just putting the  
function in curly braces.


You can use ActionScript functions as the source of data binding  
expressions when using a bindable property as an argument of the  
function. 


If you do not pass a parameter to the function then flex has no way  
of knowing when to update the function.  You can do a quick test of  
this by running this test:


?xml version=1.0 encoding=utf-8?
mx:Application xmlns:mx=http://www.adobe.com/2006/mxml;  
layout=vertical horizontalAlign=center

mx:Script
![CDATA[

[Bindable]
public var myData:String = 'old data';

private function myFunction(data:String = null):String{
return myData;
}

]]
/mx:Script
mx:Label text={myData} /
mx:Label text={myFunction(myData)} /
mx:Label text={myFunction()} /
mx:Button label=Test click=myData = 'new data'; /
/mx:Application

as you can see the first two labels will update correctly because  
they have a reference to some underlying data.  When that data  
changes Flex knows to execute the function again.  The other option  
(as you pasted in your last email) is to dispatch an event from a  
setter so that flex will know to update the function that relies on  
the set data:


?xml version=1.0 encoding=utf-8?
mx:Application xmlns:mx=http://www.adobe.com/2006/mxml;  
layout=vertical horizontalAlign=center

mx:Script
![CDATA[

private var _myData:String = 'old data';

public function set myData(value:String):void{
_myData = value;
dispatchEvent(new Event(myDataChanged));
}

[Bindable]
public function get myData():String{
return _myData;
}

[Bindable(event=myDataChanged)]
private function myFunction(data:String = null):String{
return _myData;
}

]]
/mx:Script
mx:Label text={myData} /
mx:Label text={myFunction(myData)} /
mx:Label text={myFunction()} /
mx:Button label=Test click=myData = 'new data'; /
/mx:Application

As you can see all the labels now update properly.

- Kevin



Re: [flexcoders] function binding toString !! Additional information

2007-12-29 Thread Frederico Garcia
Kevin escreveu:

 1st; when i use function biding (textInput 
 text={myInstance.toString()}/) , function binding works fine

 are you sure about that?  I could be wrong, but I would guess that if 
 you add a button under the TextInput tag your TextInput text value 
 will not update as expected on the button click.

 mx:Button label=Test click=myInstance.someProperty = 'testing'; /

 (If in fact it does update for you, I would love to see your example 
 code since it's possible there is an aspect of binding that I am missing.)

 HOWEVER, the problem you are having with the item renderer is somewhat 
 related, but different, problem.  Item renderers use 'data'  as 
 generic object to hold the data passed to the item render.  That 
 object itself is bindable AND if the entire data object changes the 
 functions and properties will update.  However, changes to the 
 underlying properties or functions will not be detected without 
 setting up binding a little more explicitly.  (Usually you don't get 
 compiler warnings, but it you run in debug mode you should get run 
 time messages in the console)  My solution to this is to explicitly 
 bind the data property to an internal property of the item renderer 
 using MXML.  When I do this the binding works correctly.

 In my item renderer...

 mx:Script
 ![CDATA[
 [Bindable]
 private var myInternalData:MyCustomClass;
 ]]
 /mx:Script
 mx:Binding source=(data as MyCustomClass) source=myInternalData /
 mx:Label text={myInternalData.myFunction()} /

 Hopefully that helps your item renderer problem.

 You are correct.  Functions can be bound BUT I think what Frederico 
 was pointing out is that there are some important things to understand 
 when binding with functions (which are stated in the document that you 
 referenced.)  It is not as easy as just putting the function in curly 
 braces.

 You can use ActionScript functions as the source of data binding 
 expressions *when using a bindable property** as an argument* of the 
 function. 

 If you do not pass a parameter to the function then flex has no way of 
 knowing when to update the function.  You can do a quick test of this 
 by running this test:

 ?xml version=1.0 encoding=utf-8?
 mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; 
 layout=vertical horizontalAlign=center
 mx:Script
 ![CDATA[


 [Bindable]
 public var myData:String = 'old data';


 private function myFunction(data:String = null):String{
 return myData;
 }


 ]]
 /mx:Script
 mx:Label text={myData} /
 mx:Label text={myFunction(myData)} /
 mx:Label text={myFunction()} /
 mx:Button label=Test click=myData = 'new data'; /
 /mx:Application

 as you can see the first two labels will update correctly because they 
 have a reference to some underlying data.  When that data changes Flex 
 knows to execute the function again.  The other option (as you pasted 
 in your last email) is to dispatch an event from a setter so that flex 
 will know to update the function that relies on the set data:

 ?xml version=1.0 encoding=utf-8?
 mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; 
 layout=vertical horizontalAlign=center
 mx:Script
 ![CDATA[


 private var _myData:String = 'old data';


 public function set myData(value:String):void{
 _myData = value;
 dispatchEvent(new Event(myDataChanged));
 }


 [Bindable]
 public function get myData():String{
 return _myData;
 }

 [Bindable(event=myDataChanged)]
 private function myFunction(data:String = null):String{
 return _myData;
 }


 ]]
 /mx:Script
 mx:Label text={myData} /
 mx:Label text={myFunction(myData)} /
 mx:Label text={myFunction()} /
 mx:Button label=Test click=myData = 'new data'; /
 /mx:Application

 As you can see all the labels now update properly.

 - Kevin

 

 __ NOD32 2755 (20071229) Information __

 This message was checked by NOD32 antivirus system.
 http://www.eset.com
Thanks Kevin,

Great post on function binding.

I believe function binding is quite cool, BUT troublesome and needless. 
Binding a property to a function with no parameters is the same as 
binding to a getter. Most Binding issues can be solved using the 
solution I first provided.

Regards,

Frederico Garcia


Re: [flexcoders] function binding toString !! Additional information

2007-12-28 Thread yigit

http://127.0.0.1:49661/help/index.jsp?topic=/com.adobe.flexbuilder.help/html/databinding_4.html
here; in the first example, there is a bindable function and it is not a 
setter or getter.

so functions other then setters and getters can be binded!
so my question should have an answer...

by the way, i'm dont have to use function biding, i can make thinks work 
without it, but when i saw it
i decided to use, cuz it is cool :) , and good in terms of code 
readiblity...


so , check out te following example, an event triggers the binding of 
the function and the function(is Enabled) is neither a getter

or a setter:

?xml version=1.0?
!-- binding/ASFunction.mxml --
mx:Application xmlns:mx=http://www.adobe.com/2006/mxml;

   mx:Script
   ![CDATA[
   import flash.events.Event;
   
   // Define a function that gets invoked 
   // in response to the myFlagChanged event.

   [Bindable(event=myFlagChanged)]
   private function isEnabled():String {
   if (myFlag)
   return 'true';
   else
   return 'false';
   }

   private var _myFlag:Boolean = false;

   // Define a setter method that dispatches the 
   // myFlagChanged event to trigger the data binding.

   public function set myFlag(value:Boolean):void {
   _myFlag = value;
   dispatchEvent(new Event(myFlagChanged));
   }

   public function get myFlag():Boolean {
   return _myFlag;
   }
   ]]
   /mx:Script


   !-- Use the function as the source of a data binding expression. --
   mx:TextArea id=myTA text={isEnabled()}/

   !-- Modify the property, causing the setter method to 
   dispatch the myFlagChanged event to trigger data binding. --

   mx:Button label=Clear MyFlag click=myFlag=false;/
   mx:Button label=Set MyFlag click=myFlag=true;/
/mx:Application



Frederico Garcia wrote On 12/27/2007 02:57 PM:


yigit escreveu:
 i think i'm misunderstood; because your solution suggestions does not
 fit my problem.
 first of all, functions can be binded. (with an event driven
 architecture that triggers
 the function to be executed and all bindable references be updated)
 to see how it is done, take a look at the article in flex api :
 
http://127.0.0.1:64744/help/index.jsp?topic=/com.adobe.flexbuilder.help/html/databinding_4.html 
http://127.0.0.1:64744/help/index.jsp?topic=/com.adobe.flexbuilder.help/html/databinding_4.html

 (or search for [Bindable] function then click the second result)

 after this quick information, i want to refigure my problem.
 assume: myInstance:MyClass; //MyClass implements a bindable toString
 method

 my problem has two parts:
 1st; when i use function biding (textInput
 text={myInstance.toString()}/) , function binding works fine
 except the itemRenderer (textInput text={data.toString()}/)
 why? what is the problem? can't the VM detect the binding mechanism?
 (by the way there isn't any compile time
 warnings about the binding will not be able to run properly)

 2nd: if i do not write toString (textInput text={myINstance}/),
 although it calls toString method to find the
 text value, function binding does never work (neither in itemRenderers
 nor normal usage).
 why? why cant the compiler detect the binding?

 thnks in advance.


 Frederico Garcia wrote On 12/26/2007 05:38 PM:

 Jhonny Everson escreveu:
 
  I guess that your solution has a problem, the circular reference to
  toString.
 
  it could be something like:
 
  [Bindable] public var stringValue:String = ;
  public function toString():String {
 
  ... ( some processing that results in a string var 'string1')
 
  stringValue= string1;
  return stringValue;
  }
 
 
  On 12/26/07, * Frederico Garcia* [EMAIL PROTECTED] 
mailto:fmotagarcia%40kemelyon.com

 mailto:fmotagarcia%40kemelyon.com
  mailto:[EMAIL PROTECTED] mailto:fmotagarcia%40kemelyon.com
 mailto:fmotagarcia%40kemelyon.com wrote:
 
  yigit escreveu:
   hi all;
   i have a custom class which has a toString method; so i can
  directly use
   it as a source to textInput's text field.
   i want to make binding work, i mean when the result of the toString
   changes, i want the view to update itself automatically.
   nameID field of roleRef is an instance of my class that implements
   toString with function biding.
   when i use this way:
   mx:Label id=lbl text={roleRef.nameID}/
   function binding on toString does not work
   when i use this way:
   mx:Label id=lbl text={roleRef.nameID.toString()}/
   function biding on toString works, but inside an item renderer,
  it does
   not work.
   mx:Label id=lbl text={data.nameID.toString()}/
  
  
   is this a compiler bug or is this the normal behavior?
  
  
   --
   Flexcoders Mailing List
   FAQ:
  http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt 
http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
 

Re: [flexcoders] function binding toString !! Additional information

2007-12-28 Thread Johannes Nel
override the set data function in your item renderer and bind your function
getter to an event you dispatch in there.

On Dec 27, 2007 2:39 AM, yigit [EMAIL PROTECTED] wrote:

i think i'm misunderstood; because your solution suggestions does not
 fit my problem.
 first of all, functions can be binded. (with an event driven architecture
 that triggers
 the function to be executed and all bindable references be updated)
 to see how it is done, take a look at the article in flex api :

 http://127.0.0.1:64744/help/index.jsp?topic=/com.adobe.flexbuilder.help/html/databinding_4.html
 (or search for [Bindable] function then click the second result)

 after this quick information, i want to refigure my problem.
 assume: myInstance:MyClass; //MyClass implements a bindable toString
 method

 my problem has two parts:
 1st; when i use function biding (textInput text={myInstance.toString()}/)
 , function binding works fine
 except the itemRenderer (textInput text={data.toString()}/)
 why? what is the problem? can't the VM detect the binding mechanism? (by
 the way there isn't any compile time
 warnings about the binding will not be able to run properly)

 2nd: if i do not write toString (textInput text={myINstance}/),
 although it calls toString method to find the
 text value, function binding does never work (neither in itemRenderers nor
 normal usage).
 why? why cant the compiler detect the binding?

 thnks in advance.


 Frederico Garcia wrote On 12/26/2007 05:38 PM:

  Jhonny Everson escreveu:
 
  I guess that your solution has a problem, the circular reference to
  toString.
 
  it could be something like:
 
  [Bindable] public var stringValue:String = ;
  public function toString():String {
 
  ... ( some processing that results in a string var 'string1')
 
  stringValue= string1;
  return stringValue;
  }
 
 
  On 12/26/07, * Frederico Garcia* [EMAIL 
  PROTECTED]fmotagarcia%40kemelyon.com
  mailto:[EMAIL PROTECTED] fmotagarcia%40kemelyon.com wrote:
 
  yigit escreveu:
   hi all;
   i have a custom class which has a toString method; so i can
  directly use
   it as a source to textInput's text field.
   i want to make binding work, i mean when the result of the toString
   changes, i want the view to update itself automatically.
   nameID field of roleRef is an instance of my class that implements
   toString with function biding.
   when i use this way:
   mx:Label id=lbl text={roleRef.nameID}/
   function binding on toString does not work
   when i use this way:
   mx:Label id=lbl text={roleRef.nameID.toString()}/
   function biding on toString works, but inside an item renderer,
  it does
   not work.
   mx:Label id=lbl text={data.nameID.toString()}/
  
  
   is this a compiler bug or is this the normal behavior?
  
  
   --
   Flexcoders Mailing List
   FAQ:
  http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
  http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
   Search Archives:
  http://www.mail-archive.com/flexcoders%40yahoogroups.com
   Yahoo! Groups Links
  
  
  
  
   __ NOD32 2747 (20071225) Information __
  
   This message was checked by NOD32 antivirus system.
   http://www.eset.com
  
  
  
  
  I believe you can only bind vars and setters. By binding a function i
  think it will only execute the function once. An easy workaround
  is to
  have a var containg the result of the toString function and bind the
  property to that var. Something like:
 
  [Bindable] public var stringValue:String = ;
  public function toString():String {
  stringValue= this.toString();
  return stringValue;
  }
 
  mx:Label id=lbl text={data.nameID.stringValue}/
 
  Regards
 
  Frederico Garcia
 
 
 
 
  --
  Jhonny Everson
 
  __ NOD32 2747 (20071225) Information __
 
  This message was checked by NOD32 antivirus system.
  http://www.eset.com
 Yes, indeed there was a circular reference to toString. Thanks for the
 correction. The general concept is the same though, and I think it's the
 best way to solve the bind to function problem.

 Regards

 Frederico Garcia


  




-- 
j:pn
\\no comment


Re: [flexcoders] function binding toString !! Additional information

2007-12-27 Thread Frederico Garcia
yigit escreveu:
 i think i'm misunderstood; because your solution suggestions does not 
 fit my problem.
 first of all, functions can be binded. (with an event driven 
 architecture that triggers
 the function to be executed and all bindable references be updated)
 to see how it is done, take a look at the article in flex api :
 http://127.0.0.1:64744/help/index.jsp?topic=/com.adobe.flexbuilder.help/html/databinding_4.html
 (or search for [Bindable] function then click the second result)

 after this quick information, i want to refigure my problem.
 assume: myInstance:MyClass; //MyClass implements a bindable toString 
 method

 my problem has two parts:
 1st; when i use function biding (textInput 
 text={myInstance.toString()}/) , function binding works fine
 except the itemRenderer (textInput text={data.toString()}/)
 why? what is the problem? can't the VM detect the binding mechanism? 
 (by the way there isn't any compile time
 warnings about the binding will not be able to run properly)

 2nd: if i do not write toString (textInput text={myINstance}/), 
 although it calls toString method to find the
 text value, function binding does never work (neither in itemRenderers 
 nor normal usage).
 why? why cant the compiler detect the binding?

 thnks in advance.


 Frederico Garcia wrote On 12/26/2007 05:38 PM:

 Jhonny Everson escreveu:
 
  I guess that your solution has a problem, the circular reference to
  toString.
 
  it could be something like:
 
  [Bindable] public var stringValue:String = ;
  public function toString():String {
 
  ... ( some processing that results in a string var 'string1')
 
  stringValue= string1;
  return stringValue;
  }
 
 
  On 12/26/07, * Frederico Garcia* [EMAIL PROTECTED] 
 mailto:fmotagarcia%40kemelyon.com
  mailto:[EMAIL PROTECTED] 
 mailto:fmotagarcia%40kemelyon.com wrote:
 
  yigit escreveu:
   hi all;
   i have a custom class which has a toString method; so i can
  directly use
   it as a source to textInput's text field.
   i want to make binding work, i mean when the result of the toString
   changes, i want the view to update itself automatically.
   nameID field of roleRef is an instance of my class that implements
   toString with function biding.
   when i use this way:
   mx:Label id=lbl text={roleRef.nameID}/
   function binding on toString does not work
   when i use this way:
   mx:Label id=lbl text={roleRef.nameID.toString()}/
   function biding on toString works, but inside an item renderer,
  it does
   not work.
   mx:Label id=lbl text={data.nameID.toString()}/
  
  
   is this a compiler bug or is this the normal behavior?
  
  
   --
   Flexcoders Mailing List
   FAQ:
  http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt 
 http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
  http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt 
 http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
   Search Archives:
  http://www.mail-archive.com/flexcoders%40yahoogroups.com 
 http://www.mail-archive.com/flexcoders%40yahoogroups.com
   Yahoo! Groups Links
  
  
  
  
   __ NOD32 2747 (20071225) Information __
  
   This message was checked by NOD32 antivirus system.
   http://www.eset.com http://www.eset.com
  
  
  
  
  I believe you can only bind vars and setters. By binding a function i
  think it will only execute the function once. An easy workaround
  is to
  have a var containg the result of the toString function and bind the
  property to that var. Something like:
 
  [Bindable] public var stringValue:String = ;
  public function toString():String {
  stringValue= this.toString();
  return stringValue;
  }
 
  mx:Label id=lbl text={data.nameID.stringValue}/
 
  Regards
 
  Frederico Garcia
 
 
 
 
  --
  Jhonny Everson
 
  __ NOD32 2747 (20071225) Information __
 
  This message was checked by NOD32 antivirus system.
  http://www.eset.com http://www.eset.com
 Yes, indeed there was a circular reference to toString. Thanks for the
 correction. The general concept is the same though, and I think it's the
 best way to solve the bind to function problem.

 Regards

 Frederico Garcia


 

 __ NOD32 2747 (20071225) Information __

 This message was checked by NOD32 antivirus system.
 http://www.eset.com
Hi,

Functions are indeed bindable, but only special function are: getters 
and setters. If you look carefully in the help topic you siggested the 
example there is:

|* [Bindable(event=maxFontSizeChanged)]*| // Define public getter 
method. |* public function get maxFontSize():Number {*| return 
_maxFontSize; }

This, however is not what you want, since getters and setters work the 
same way as vars, only they execute some code.

Using getters you could do something like:

[Bindable(event=changeEvent)]
public function get asString():String {
... ( some processing that results in a string var 'string1')   
return string1;
}

every time you change the 

Re: [flexcoders] function binding toString !! Additional information

2007-12-26 Thread yigit
i think i'm misunderstood; because your solution suggestions does not 
fit my problem.
first of all, functions can be binded. (with an event driven 
architecture that triggers

the function to be executed and all bindable references be updated)
to see how it is done, take a look at the article in flex api :
http://127.0.0.1:64744/help/index.jsp?topic=/com.adobe.flexbuilder.help/html/databinding_4.html
(or search for [Bindable] function then click the second result)

after this quick information, i want to refigure my problem.
assume: myInstance:MyClass; //MyClass implements a bindable toString method

my problem has two parts:
1st; when i use function biding (textInput 
text={myInstance.toString()}/) , function binding works fine

except the itemRenderer (textInput text={data.toString()}/)
why? what is the problem? can't the VM detect the binding mechanism? (by 
the way there isn't any compile time

warnings about the binding will not be able to run properly)

2nd: if i do not write toString (textInput text={myINstance}/), 
although it calls toString method to find the
text value, function binding does never work (neither in itemRenderers 
nor normal usage).

why? why cant the compiler detect the binding?

thnks in advance.


Frederico Garcia wrote On 12/26/2007 05:38 PM:


Jhonny Everson escreveu:

 I guess that your solution has a problem, the circular reference to
 toString.

 it could be something like:

 [Bindable] public var stringValue:String = ;
 public function toString():String {

 ... ( some processing that results in a string var 'string1')

 stringValue= string1;
 return stringValue;
 }


 On 12/26/07, * Frederico Garcia* [EMAIL PROTECTED] 
mailto:fmotagarcia%40kemelyon.com
 mailto:[EMAIL PROTECTED] 
mailto:fmotagarcia%40kemelyon.com wrote:


 yigit escreveu:
  hi all;
  i have a custom class which has a toString method; so i can
 directly use
  it as a source to textInput's text field.
  i want to make binding work, i mean when the result of the toString
  changes, i want the view to update itself automatically.
  nameID field of roleRef is an instance of my class that implements
  toString with function biding.
  when i use this way:
  mx:Label id=lbl text={roleRef.nameID}/
  function binding on toString does not work
  when i use this way:
  mx:Label id=lbl text={roleRef.nameID.toString()}/
  function biding on toString works, but inside an item renderer,
 it does
  not work.
  mx:Label id=lbl text={data.nameID.toString()}/
 
 
  is this a compiler bug or is this the normal behavior?
 
 
  --
  Flexcoders Mailing List
  FAQ:
 http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt 
http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
 http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt 
http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt

  Search Archives:
 http://www.mail-archive.com/flexcoders%40yahoogroups.com 
http://www.mail-archive.com/flexcoders%40yahoogroups.com

  Yahoo! Groups Links
 
 
 
 
  __ NOD32 2747 (20071225) Information __
 
  This message was checked by NOD32 antivirus system.
  http://www.eset.com http://www.eset.com
 
 
 
 
 I believe you can only bind vars and setters. By binding a function i
 think it will only execute the function once. An easy workaround
 is to
 have a var containg the result of the toString function and bind the
 property to that var. Something like:

 [Bindable] public var stringValue:String = ;
 public function toString():String {
 stringValue= this.toString();
 return stringValue;
 }

 mx:Label id=lbl text={data.nameID.stringValue}/

 Regards

 Frederico Garcia




 --
 Jhonny Everson

 __ NOD32 2747 (20071225) Information __

 This message was checked by NOD32 antivirus system.
 http://www.eset.com http://www.eset.com
Yes, indeed there was a circular reference to toString. Thanks for the
correction. The general concept is the same though, and I think it's the
best way to solve the bind to function problem.

Regards

Frederico Garcia