0 Replies Latest reply on May 2, 2012 1:05 PM by tyuiop86

    Custom attribute in a custom component never gets set up

    tyuiop86

      I created a custom numericStepper extending Spark numericStepper, code below:

       

      package view.component.controls

      {

                import flash.events.FocusEvent;

                import flash.events.MouseEvent;

       

                import spark.components.NumericStepper;

       

       

                public class CustomNumericStepper extends NumericStepper

                {

                public var preventKeyDown:Boolean=false;

       

                public function CustomNumericStepper ()

                 {

                                                   super();

                  }

       

                                    override protected function focusInHandler(event:FocusEvent):void

                                    {

                                                   super.focusInHandler(event);


                                                   if(this.textDisplay.text == "0")

                                                                  this.textDisplay.text = "";

                    }

       

                                    override protected function childrenCreated():void

                                    {

                                                   super.childrenCreated();


                                                   this.textDisplay.restrict="0-9";

                                    }

       

                                    override protected function system_mouseWheelHandler(event:MouseEvent):void

                   {

                                                   event.preventDefault();


                                                   super.system_mouseWheelHandler(event);

                                    }

       

                    override protected function keyDownHandler(event:KeyboardEvent):void

                    {

                                                   if(preventKeyDown)

                                                                  event.preventDefault();

                                                   else

                                                                  super.keyDownHandler(event);

                    }

       

         }

      }

       

       

      The problem that I'm having is that the preventKeyDown attribute never gets the value set up in the MXML where I use this custom numeric stepper. I'm using it in an itemRenderer inside a DataGrid. Code below:

       

      <mx:DataGridColumn headerText="{resourceManager.getString('Template', 'Qty')}"  width="80" editorDataField="value" dataField="Quantity"

                                                                                                   textAlign="center" visible="{hasPermission(UserProxy.ORDER_TEMPLATES, UserProxy.UPDATE)}">

                                                                       <mx:itemRenderer>

                                                                                      <fx:Component>

                                                                                                     <mx:HBox paddingLeft="5" paddingRight="5" horizontalAlign="center">

                                                                                                                    <fx:Script>

                                                                                                                              <![CDATA[

                                                                                                                                        import model.UserProxy;

       

                                                                                                                                        import mx.controls.listClasses.IListItemRenderer;

                                                                                                                                        import mx.resources.ResourceManager;

       

                                                                                                                                        import view.component.controls.IBSADataGrid;

       

                                                                                                                                        override public function set data(value:Object):void

                                                                                                                                        {

                                                                                                                                                  super.data = value;

                                                                                                                                                  if(data)

                                                                                     {

                                                                                                                                        if(data.IsObsoleteItem.t oString() == "true")

                                                                                                                                        {

                                                                                                                                                  txtQty.enabled = false;

                                                                                                                                                  txtQty.setStyle('co ntentBackgroundColor', '#aaaaaa');

                                                                                                                                                  this.toolTip = ResourceManager.getInstance().getString('Template', 'tooltip_obsolete');

                                                                                                                                        }

                                                                                                                                        else if(!outerDocument.hasPermission(UserProxy.ALLOW_RESTRICTED, UserProxy.SEE_RESTRICTED_PRODUCTS) && data.Product.IsAdminData.toString() ==                                                                          "true")

                                                                                                                                        {

                                                                                                                                                  txtQty.enabled = false;

                                                                                                                                                  txtQty.setStyle('co ntentBackgroundColor', '#aaaaaa');

                                                                                                                                                  this.toolTip = ResourceManager.getInstance().getString('Template', 'tooltip_admin_data');

                                                                                                                                        }

                                                                                                                                        else

                                                                                                                                        {

                                                                                                                                                  txtQty.enabled = true;

                                                                                                                                                  txtQty.setStyle('co ntentBackgroundColor', 'white');

                                                                                                                                        }

                                                                                                                              }

                                                                                                                    }

       

                                                                                                                    protected function txtQty_keyFocusChangeHandler(event:FocusEvent):void

                                                                                                                    {

                                                                                                                              event.preventDefault();

       

                                                                                                                              var templateDetailsGrid:IBSADataGrid = this.owner as IBSADataGrid;

                                                                                                                              var index:int = templateDetailsGrid.itemRendererToIndex(this as IListItemRenderer);

                                                                                                                              var nextFocusComponent:Object;

                                                                                                                              var colIndex:int;

       

                                                                                                                              if(outerDocument.dgColTemplat eID.visible)

                                                                                                                                        colIndex = 3;

                                                                                                                              else

                                                                                                                                        colIndex = 4;

       

                                                                                                                              if(event.shiftKey)

                                                                                                                                        nextFocusComponent = templateDetailsGrid.indexToItemRendererAtColumn(index-1, templateDetailsGrid.columnCount-colIndex);

                                                                                                                              else

                                                                                                                                        nextFocusComponent = templateDetailsGrid.indexToItemRendererAtColumn(index+1, templateDetailsGrid.columnCount-colIndex);

       

                                                                                                                              if(nextFocusComponent)

                                                                                                                                        focusManager.setFocus(ne xtFocusComponent.txtQty);

                                                                                                                              else

                                                                                                                              {

                                                                                                                                        if(event.shiftKey)

                                                                                                                                        {

                                                                                                                                                  //scroll up

                                                                                                                                                  if(templateDetailsG rid.verticalScrollPosition > 0)

                                                                                                                                                  {

                                                                                                                                                            templateDetail sGrid.verticalScrollPosition--;

                                                                                                                                                            //try to focus in the next renderer after scrolling

                                                                                                                                                            nextFocusCompo nent = templateDetailsGrid.indexToItemRendererAtColumn(index-1, templateDetailsGrid.columnCount-5);

                                                                                                                                                            if(nextFocusCo mponent)

                                                                                                                                                                      focusMana ger.setFocus(nextFocusComponent.txtQty);

                                                                                                                                                  }

                                                                                                                                        }

                                                                                                                                        else

                                                                                                                                        {

                                                                                                                                                  //scroll down

                                                                                                                                                  if(templateDetailsG rid.verticalScrollPosition < templateDetailsGrid.maxVerticalScrollPosition)

                                                                                                                                                  {

                                                                                                                                                            templateDetail sGrid.verticalScrollPosition++;

                                                                                                                                                            //try to focus in the next renderer after scrolling

                                                                                                                                                            nextFocusCompo nent = templateDetailsGrid.indexToItemRendererAtColumn(index+1, templateDetailsGrid.columnCount-5);

                                                                                                                                                            if(nextFocusCo mponent)

                                                                                                                                                                      focusMana ger.setFocus(nextFocusComponent.txtQty);

                                                                                                                                                  }

                                                                                                                                        }

                                                                                                                              } 

                                                                                                                    }

                                                                                                          ]]>

                                                                                                </fx:Script>

                                                                                                <local:CustomNumericStepper id="txtQty" width="70" value="{data.Quantity}" preventKeyDown="true"

                                                                                                                                                              verticalCenter="0" horizontalCenter="0" textAlign="left" tabIndex="1" stepSize="1" maximum="999999" maxChars="6"

                                                                                                                                                              change="outerDocument.txtQty_changeHandler(txtQty.textDisplay.text, data.ID, data.Quantity)"

                                                                                                                                                              keyFocusChange="txtQty_keyFocusChangeHandler(event)"/>

                                                                                      </mx:HBox>

                                                                            </fx:Component>

                                                                  </mx:itemRenderer>

                                                        </mx:DataGridColumn>

       

      When I'm typing in the MXML, FlashBuilder recognize the custom attribute as it is listed in the intellisense, however that attribute is never set up. I tried looking into the value in events such as childrenCreated, commitProperties, etc but it's always false.

       

      Am I missing something here ? Please help !! Thanks.. Sorry for the long post