0 Replies Latest reply on Jan 23, 2011 10:53 PM by DevIsFun

    How do I create data-driven linkbuttons whose visibility is controlled from the front end?

    DevIsFun

      I've made a component based on a mx:TitleWindow that contains linkbuttons that I'm using as a context-menu.

       

      The TitleWindow component contains link buttons like this:

       

      [Bindable] 
      private var _showEmailThis:Boolean = false;

      [Bindable]
      private var _showApproveThis:Boolean = false;

      [Bindable]
      private var _showReviewThis:Boolean = false;

      <mx:LinkButton id="lnkEmailThis" 
                     visible
      ="{_showEmailThis}" 
                     includeInLayout
      ="{_showEmailThis}" 
                     click
      ="lnkEmailThis_click()" 
                     label
      ="Email this!" />

      <mx:LinkButton id="lnkApproveThis" 
                     visible
      ="{_showApproveThis}" 
                     includeInLayout
      ="{_showApproveThis}" 
                     click
      ="lnkApproveThis_click()" 
                     label
      ="Approve this!" />

      <mx:LinkButton id="lnkReviewThis" 
                     visible
      ="{_showReviewThis}" 
                     includeInLayout
      ="{_showReviewThis}" 
                     click
      ="lnkReviewThis_click()" 
                     label
      ="Review this!" />

      This component contains a large number of links and is re-used by multiple modules in the same application.

      Within each module, this component is used when a user clicks on a row in a datagrid.

       

      The code looks like this:

       

      In "Requests" module:

      private function dgRequests_click(event:MouseEvent):void 
      {
          menu
      .showApproveThis = true;
          menu
      .showReviewThis = true;
      }

      In "Performance" module:

      private function dgPerformance_click(event:MouseEvent):void 
      {
          menu
      .showEmailThis = true;
          menu
      .showReviewThis = true;
      }

      As you can see, the visibility of individual linkbuttons is controlled within each module by setting boolean properties.

      If I alter this component to use a renderer, how can I control the visibility of the linkbuttons from the code in each module (there are over a hundred links with different functionality - not every link will be used in each module)? Note: it is not known from the back-end which grid within which module uses which link. This is set in the front end within each module's actionscript file.

       

      e.g., if the XML looks like this:

      <links> 
        
      <link>
           
      <label>Email This</label>
            <visible>_showEmailThis</
      visible>
        
      </link>
         <link>
            <label>Approve This</
      label>
           
      <visible>_showApproveThis</visible>
         </
      link>
        
      <link>
           
      <label>Review This</label>
            <visible>_showReviewThis</
      visible>
        
      </link>
      </
      links>

      and I set the Email link to show in the module like this:

      private function dgPerformance_click(event:MouseEvent):void 
      {
          menu
      .showEmailThis = true;
      }

      How do I make it take effect? Is there a way to control the visibility of a linkbutton within an item renderer in a component from the module that uses that component? Is there something like reflection in the Flex framework?