6 Replies Latest reply on Oct 14, 2008 10:37 AM by Peter Lorent

    Adding a mask in a datagrid

    SiHoop Level 1
      The first code block is an item renderer that is used to place a button into a datagrid. The second code block is a class that adds some interactivity to the button. The second code block also contains two commented out lines where I have attempted to add a mask to the button. My problem is that at present I am adding the mask inside the button, whereas I would like the mask to be outside the button (i.e. in the datagrid so I can animate the button to a different state when it is clicked). I cannot figure out where I should put the mask (I assume that it should go in the button renderer) but have no idea where or how to place it. Can anyone point me in the right direction?
      Thanks!
        • 1. Re: Adding a mask in a datagrid
          Level 7

          "SiHoop" <webforumsuser@macromedia.com> wrote in message
          news:gd0vg1$5or$1@forums.macromedia.com...
          > The first code block is an item renderer that is used to place a button
          > into a
          > datagrid. The second code block is a class that adds some interactivity to
          > the
          > button. The second code block also contains two commented out lines where
          > I
          > have attempted to add a mask to the button. My problem is that at present
          > I am
          > adding the mask inside the button, whereas I would like the mask to be
          > outside
          > the button (i.e. in the datagrid so I can animate the button to a
          > different
          > state when it is clicked). I cannot figure out where I should put the mask
          > (I
          > assume that it should go in the button renderer) but have no idea where or
          > how
          > to place it. Can anyone point me in the right direction?

          The masking object would need to be in the canvas (outside of the button).

          HTH;

          Amy


          • 2. Re: Adding a mask in a datagrid
            Peter Lorent Level 2
            Yes, use the graphics object of the item renderer (Canvas) to draw a mask and set that mask on dg_Button
            • 3. Re: Adding a mask in a datagrid
              SiHoop Level 1
              I cannot figure out where I am supposed to set the mask! If I try to set it in the Button:
              <local:MovieClipExample styleName="style1" id="dg_Button" width="65" mask="square" click="onChange(event)"
              useHandCursor="true" buttonMode="true" mouseChildren="false" />

              I get the error: Initializer for 'mask': values of type flash.display.DisplayObject cannot be represented in text.

              If I try to set it in the setter with :
              public function set listData( value:BaseListData ):void {
              dg_Button.mask=square
              _listData = value;
              myDataGrid = _listData.owner as MyDataGrid;
              key=_listData.uid;
              }

              I get the error: Access of undefined property square even if I make square public.
              • 4. Re: Adding a mask in a datagrid
                Peter Lorent Level 2
                I would use an init() as listener function on the creationComplete event of the renderer.

                If you want to set it in the button: mask="{square}"
                • 5. Re: Adding a mask in a datagrid
                  SiHoop Level 1
                  I tried that, but got the following error which seems to be directly related to dg_Button.mask="{square}":
                  Implicit coercion of a value of type String to an unrelated type flash.display:DisplayObject.
                  What am I doing wrong to prevent the mask from workin?
                  Thanks again!



                  • 6. Re: Adding a mask in a datagrid
                    Peter Lorent Level 2
                    Yes, that wouldn't work then.
                    try:
                    public function init():void {
                    square = new Sprite();
                    square.graphics.beginFill(0xFF0000);
                    square.graphics.drawRect(0, 0, 50, 26); //set the correct coordinates for the square
                    addChild(square);
                    dg_Button.mask = square;
                    }

                    and remove the square from the MovieClipExample.as