Re: [flexcoders] Binding to a custom method: possible?

2006-11-29 Thread Lachlan Cotter

Hi Ben,

Your problem is probably that you have not told Flex when it needs to  
fire the binding. The binding mechanism works by broadcasting events  
from the setter methods of bindable properties. If there is no direct  
setter involved, then Flex does not automatically know to refresh the  
data to the binding destination.


The best way I know around this issue is to specify the event type  
you want to associate with a change to your calculated value, and  
then fire that event when ever any of the arguments to that method  
change.


[Bindable(enabledParamsChanged)]
private function isEnabled():Boolean {
if (A) … if (B) … etc
}

Then you need to say something like

private function set valueOfA (arg) {
// Change A here
dispatchEvent(new Event(enabledParamsChanged));
}

private function set valueOfB (arg) {
// Change B here
dispatchEvent(new Event(enabledParamsChanged));
}

Now Flex knows to fire your isEnabled binding when the arguments to  
the calculation are altered.


Cheers,
Lach


On 29/11/2006, at 1:13 AM, ben.clinkinbeard wrote:


There was a similar question asked here recently but my needs are
different so I am starting a new thread. My needs are as follows: I
have a ComboBox whose enabled state needs to be determined by several
factors, thus the need for a custom method. The problem is that this
doesn't seem to work, no matter how I try it. Am I missing something
or is this just not possible (meaning I have to set a property and
bind to that)? Fake sample code below:

[Bindable]
private function isEnabled():Boolean
{
if(conditionA)
{
if(conditionB)
{
return true;
}
else
{
return false;
}
}
}

mx:ComboBox id=cb enabled={isEnabled()}/

Thanks,
Ben




[flexcoders] Binding to a custom method: possible?

2006-11-28 Thread ben.clinkinbeard
There was a similar question asked here recently but my needs are
different so I am starting a new thread. My needs are as follows: I
have a ComboBox whose enabled state needs to be determined by several
factors, thus the need for a custom method. The problem is that this
doesn't seem to work, no matter how I try it. Am I missing something
or is this just not possible (meaning I have to set a property and
bind to that)? Fake sample code below:

[Bindable]
private function isEnabled():Boolean
{
   if(conditionA)
   {
  if(conditionB)
  {
 return true;
  }
  else
  {
 return false;
  }
   }
}

mx:ComboBox id=cb enabled={isEnabled()}/


Thanks,
Ben



Re: [flexcoders] Binding to a custom method: possible?

2006-11-28 Thread slangeberg

In this case, your function is not referencing anything Bindable. Something
like this may work, but please clarify - if this is not what you're looking
for:

[Bindable]
private var bindableProp:String;

private function isEnabled( s:String ):Boolean
{
...
}

mx:ComboBox id=cb enabled={isEnabled( bindableProp )}/

On 11/28/06, ben.clinkinbeard [EMAIL PROTECTED] wrote:


  There was a similar question asked here recently but my needs are
different so I am starting a new thread. My needs are as follows: I
have a ComboBox whose enabled state needs to be determined by several
factors, thus the need for a custom method. The problem is that this
doesn't seem to work, no matter how I try it. Am I missing something
or is this just not possible (meaning I have to set a property and
bind to that)? Fake sample code below:

[Bindable]
private function isEnabled():Boolean
{
if(conditionA)
{
if(conditionB)
{
return true;
}
else
{
return false;
}
}
}

mx:ComboBox id=cb enabled={isEnabled()}/

Thanks,
Ben

 





--

: : ) Scott