2 Replies Latest reply on Nov 3, 2010 10:57 AM by giba_f

    itemRenderer with Script within the DataGridColumn not "see" Script of the Application.

    giba_f Level 1

      Hello everyone!

      This source below, I have a script with itemRenderer in the DataGridColumn.

      In this script I have the function ChkMark() that I need to use the ListNames:ArrayCollection, that is in script of the application, but inside she is not "visible."

      What must I do to fix this?

      Source:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:TitleWindow xmlns:mx="
      http://www.adobe.com/2006/mxml" layout="absolute" width="664" height="480"  >
         
          <mx:DataGrid x="6" y="199" height="115" width="580" id="brw" fontSize="10" dataProvider="{ListNames}"  >
              <mx:columns>
                  <mx:DataGridColumn  width="10" >
                      <mx:itemRenderer>
                          <mx:Component>
                              <mx:Image width="10" height="10" source="{imagem.source}"
                                creationComplete="Legend();" click="Mark();" >
                                  <mx:Script>
                                      <![CDATA[

                                          import mx.rpc.events.ResultEvent;
                                          import mx.controls.Image;
                                          import mx.controls.Alert;
                                          import mx.events.*;
                                         
                                          [Bindable]public var imagem:Image = new Image();
          
                                          public function Legend():void {
                                              switch (data.mark) {
                                                  case "S":
                                                      imagem.source = "CheckOn.png";
                                                      break;
                                                  case "N":
                                                      imagem.source = "CheckOf.png";
                                                      break;
                                                  default:
                                                      imagem.source = "CheckOf.png";
                                              }
                                          }

                                          public function Mark():void {
                                              if ( data.mark == "" ) {
                                                  var lOk:Boolean = true;
                                                  if ( lOk ) {
                                                      data.mark = "S";
                                                  }
                                              }
                                              else {
                                                  data.mark = "";
                                              }
                                              Legenda();
                                          }

                                          public function ChkMark():Boolean {
                                              var lRet:Boolean = true;
                                              for ( var i:int=0 ; i < ListNames.length ; i++) {
                                                  if ( ListNames.getItemAt(i).mark == "S" ) {
                                                      lRet = false
                                                      Alert.show( "bla..bla..bla...bla..." ,'Alert.' );
                                                      break;
                                                  }
                                              }
                                              return lRet;
                                          }

                                      ]]>
                                  </mx:Script>
                              </mx:Image>
                          </mx:Component>
                      </mx:itemRenderer>
                  </mx:DataGridColumn>
                  <mx:DataGridColumn  width="40"  headerText="Cod"      dataField="cod"   />
                  <mx:DataGridColumn  width="100" headerText="Name"     dataField="name"  />
              </mx:columns>
          </mx:DataGrid>


          <mx:Script>
              <![CDATA[

                  [Bindable] public var ListNames:ArrayCollection([ { cod:"001" , name:"Name 1" , mark:" " } ,
                                                                    { cod:"002" , name:"Name 2" , mark:" " } ,
                                                                    { cod:"003" , name:"Name 3" , mark:" " } ]);
              ]]>
          </mx:Script>


      </mx:TitleWindow>

      Gilberto

       

      Since already I thank you: THANK YOU.