5 Replies Latest reply on Mar 14, 2007 1:14 PM by ctzn99

    trouble removing error please help

    ankmit
      hi,
      i am relatively new in flex. i have to display an image whose source should come from the column of a datagrid when i click the column. i tried the following code(given in flex documentation): -

      // Retrieve the image associated with the item selected in the grid.
      private function getImage():void {
      var cartGrid = dgrid;
      var imageSource:String = 'images/' + cartGrid.getSelectedIndex() + '.jpg';
      image1.load(imageSource);
      }

      and recieved the following error: -
      1008: var 'cartGrid' has no type declaration.

      i dont know what to do now please help in this regard
        • 1. Re: trouble removing error please help
          ankmit Level 1
          waiting for your response
          • 2. Re: trouble removing error please help
            ctzn99
            cartGrid needs to be declared as a specific data type, from your post it looks like it's trying to be a datagrid so the line that reads

            var cartGrid = dgrid;

            should be

            var cartGrid:DataGrid = dgrid;
            • 3. Re: trouble removing error please help
              ankmit Level 1
              thanks for this response i will try this and tell you the result

              thanks again
              • 4. Re: trouble removing error please help
                ankmit Level 1
                your code removes the previous error but gives a new one : -

                1061: Call to a possibly undefined method getSelectedIndex through a reference with static type mx.controls:DataGrid.

                probably it needs to be defined as some othere dat type i am pasting the source documentation frome where i picked the code may be that can tell you where the problem might be: -

                In the next example, you use the index number of the selected item in a data grid to determine the image to load. In this example, images are named 1.jpg, 2.jpg, 3.jpg, and so on, corresponding to items in the grid.

                // Retrieve the image associated with the item selected in the grid.
                private function getImage():void {
                var cartGrid = dgrid;
                var imageSource:String = 'images/' + cartGrid.getSelectedIndex() + '.jpg';
                image1.load(imageSource);
                }


                In this example, the images are stored in the images directory. The complete path to an image is the directory name, the index number, and the file suffix .jpg.

                You register this function as the event listener for a change event in the data grid, as follows:

                <mx:DataGrid id="dgrid" height="200" width="350" change="getImage();"/>


                When a user changes the currently selected item in the data grid, Flex calls the getImage() function to update the displayed image.



                • 5. Re: trouble removing error please help
                  ctzn99 Level 1
                  the getSelectedIndex method that you are calling isn't part of the data grid class. there is a "selectedIndex" property that I suspect is what you are looking for.

                  change.

                  var imageSource:String = 'images/' + cartGrid.getSelectedIndex() + '.jpg';

                  to

                  var imageSource:String = 'images/' + cartGrid.selectedIndex + '.jpg';

                  Good Luck,
                  Zach.