What you are trying to do may be accomplished using custom events for
data binding.  Here's an example of what I think you are looking for:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="horizontal" >
   <mx:Script>
     <![CDATA[
       private var _myBindableVar:Boolean=false;
       [Bindable]
       public function get myBindableVar():Boolean
       {
         return _myBindableVar;
       }
       public function set myBindableVar( val:Boolean ):void
       {
         if( val != _myBindableVar )
         {
           _myBindableVar = val;
           dispatchEvent( new Event("bindableVarChanged") );
         }
       }

       [Bindable("bindableVarChanged")]
       private function allowThis():Boolean
       {
         return myBindableVar == true;
       }
     ]]>
   </mx:Script>

   <mx:XMLListCollection id="dp">
     <mx:source>
       <mx:XMLList xmlns="">
         <item label="Menu" enabled="true" >
           <subitem label="Dynamic enabled state" enabled="{allowThis()}"
/>
           <subitem label="Static enabled state" enabled="true" />
         </item>
       </mx:XMLList>
     </mx:source>
   </mx:XMLListCollection>

   <mx:MenuBar dataProvider="{dp}" labelField="@label" />
   <mx:Button id="button" toggle="true" click="myBindableVar
=button.selected" />
</mx:Application>






--- In flexcoders@yahoogroups.com, Mark Carter <[EMAIL PROTECTED]> wrote:
>
>
> I have a MenuBar where the dataProvider is specified in MXML as an
XMLList.
>
> For the "enabled" attributes I do something like:
>
> enabled="{allowThis()}"
>
> However, to get databinding working I end up passing in the relevant
> bindable property and then ignore it within the implementation of
allowMe().
> For example:
>
> enabled="{allowThat(myBindableVar)}"
>
> This works, but IMHO is horrible because it requires either messing up
my
> API or creating a load of functions like:
>
> function allowThat(myBindableVar:Object):Boolean {
> allowThis();
> }
>
> Is there another approach? A standard approach?
>
> As another workaround, maybe there is a way to recalculate the enabled
flags
> for the whole MenuBar? Maybe resetting the dataProvider?
> --
> View this message in context:
http://www.nabble.com/Best-practice-for-databinding-with-MenuBar--tp2062\
2610p20622610.html
> Sent from the FlexCoders mailing list archive at Nabble.com.
>


Reply via email to