6 Replies Latest reply on Sep 29, 2008 3:11 PM by ac361

    Strange behavior in Flex Builder 3

    ac361
      I've noticed that at least in my copy of Flex Builder 3, the code-completion feature doesn't seem to work entirely correctly. I was trying to define a variable of type ListBaseContentHolder, but typing the dot "." after listClasses brought up a list of available classes -- but not ListBaseContentHolder!

      var lb:mx.controls.listClasses. // --> could not see that class here.

      All the online documentation said it was there, but Flex Builder wouldn't show it. I typed it in manually,

      var lb:mx.controls.listClasses.ListBaseContentHolder;

      and it compiled just fine. Any thoughts on what might be going on here?
        • 1. Re: Strange behavior in Flex Builder 3
          Level 7

          "curious_Lee" <webforumsuser@macromedia.com> wrote in message
          news:gbgp4o$ovm$1@forums.macromedia.com...
          > I've noticed that at least in my copy of Flex Builder 3, the
          > code-completion
          > feature doesn't seem to work entirely correctly. I was trying to define a
          > variable of type ListBaseContentHolder, but typing the dot "." after
          > listClasses brought up a list of available classes -- but not
          > ListBaseContentHolder!

          I think that one is hidden somehow. I don't think they want you using it.
          What's the goal? We might be able to tell you how to achieve it without
          using it. The only time I ever used that class, I was doing something I
          wouldn't do now that I know better.


          • 2. Re: Strange behavior in Flex Builder 3
            ac361 Level 1
            Thanks, Amy. Here's what the app needs to do: It has a DataGrid with an inline ItemRenderer in one column. The ItemRenderer contains a read-only TextInput and Browse and Upload buttons. The Browse button allows a user to select a file and the Upload button enables a file upload. Each row represents an item that need to have an image file associated with it.

            I need to reference the ItemRenderer and its TextInput to display what file was selected; in addition, each row will need to fire off a validation to ensure files with the correct extension are selected. The ID column's value from that row will be used as the filename on the server.

            I found this article that partially explains how to reference the items in an ItemRenderer: http://danonflex.com/readarticle.php?article_id=5

            The problem: How do you detect which row's ItemRenderer fired off the Click event -- in other words, which Browse button was clicked? And then how do you find that row's TextInput within the ItemRenderer?

            Thanks.
            • 3. Re: Strange behavior in Flex Builder 3
              Level 7

              "curious_Lee" <webforumsuser@macromedia.com> wrote in message
              news:gbhd6g$j1t$1@forums.macromedia.com...
              > Thanks, Amy. Here's what the app needs to do: It has a DataGrid with an
              > inline
              > ItemRenderer in one column. The ItemRenderer contains a read-only
              > TextInput and
              > Browse and Upload buttons. The Browse button allows a user to select a
              > file and
              > the Upload button enables a file upload. Each row represents an item that
              > need
              > to have an image file associated with it.
              >
              > I need to reference the ItemRenderer and its TextInput to display what
              > file
              > was selected; in addition, each row will need to fire off a validation to
              > ensure files with the correct extension are selected. The ID column's
              > value
              > from that row will be used as the filename on the server.
              >
              > I found this article that partially explains how to reference the items in
              > an
              > ItemRenderer: http://danonflex.com/readarticle.php?article_id=5
              >
              > The problem: How do you detect which row's ItemRenderer fired off the
              > Click
              > event -- in other words, which Browse button was clicked? And then how do
              > you
              > find that row's TextInput within the ItemRenderer?

              The item click event's event.target property will have a reference to the
              actual row involved. If that doesn't work for you, you can generate a
              custom event on from something happening in the renderer and pass whatever
              info you need in that event.

              HTH;

              Amy


              • 4. Re: Strange behavior in Flex Builder 3
                ac361 Level 1
                I'm trying to access the TextInput field with id="txtPhoto" when the user clicks the Button with id="btnBrowse" from inside the itemRenderer element. Here's what the DataGridColumn looks like. I seem to be able to find the parent element of the button from the event; but how do you then traverse down and find the HBox and then the TextInput within that? Further down, I have the code that I'm using to try to access the element.

                <mx:DataGridColumn headerText="Test" width="250">
                <mx:itemRenderer>
                <mx:Component>
                <mx:HBox horizontalGap="2">
                <mx:TextInput id="txtPhoto" />
                <mx:Script>
                <![CDATA[
                import mx.controls.listClasses.ListBase;
                ]]>
                </mx:Script>
                <mx:Button id="btnBrowse" label="Browse" click=" outerDocument.doBrowse( event )"/>
                <mx:Button id="btnUpload" label="Upload" click="outerDocument.doSubmit( event )"/>
                </mx:HBox>
                </mx:Component>
                </mx:itemRenderer>
                </mx:DataGridColumn>

                Here's the code that needs to access the TextInput for this specific row whose btnBrowse has been clicked,

                // Called when the "Browse" button is clicked
                public function doBrowse( event:Event ):void
                {
                file.browse();
                var lb:mx.controls.listClasses.ListBaseContentHolder = event.target.parent.parent;

                if (lb==null) return;

                // This code doesn't work -- says:
                // TypeError: Error #1010: A term is undefined and has no properties.
                for (var i:int = 0; i < lb.numChildren; i++){
                var hb:HBox = lb.listItems [0] as HBox;

                if (hb==null) continue;
                var ti:TextInput = hb.getChildAt(1) as TextInput;
                if (ti==null) continue;
                ti.text = "hello world!";
                break;
                }
                }
                • 5. Re: Strange behavior in Flex Builder 3
                  Level 7

                  "curious_Lee" <webforumsuser@macromedia.com> wrote in message
                  news:gbr2jd$qgn$1@forums.macromedia.com...
                  > I'm trying to access the TextInput field with id="txtPhoto" when the user
                  > clicks the Button with id="btnBrowse" from inside the itemRenderer
                  > element.
                  > Here's what the DataGridColumn looks like. I seem to be able to find the
                  > parent
                  > element of the button from the event; but how do you then traverse down
                  > and
                  > find the HBox and then the TextInput within that? Further down, I have the
                  > code
                  > that I'm using to try to access the element.
                  >
                  > <mx:DataGridColumn headerText="Test" width="250">
                  > <mx:itemRenderer>
                  > <mx:Component>
                  > <mx:HBox horizontalGap="2">
                  > <mx:TextInput id="txtPhoto" />
                  > <mx:Script>
                  > <![CDATA[
                  > import mx.controls.listClasses.ListBase;
                  > ]]>
                  > </mx:Script>
                  > <mx:Button id="btnBrowse" label="Browse" click="
                  > outerDocument.doBrowse( event )"/>
                  > <mx:Button id="btnUpload" label="Upload"
                  > click="outerDocument.doSubmit( event )"/>
                  > </mx:HBox>
                  > </mx:Component>
                  > </mx:itemRenderer>
                  > </mx:DataGridColumn>
                  >
                  > Here's the code that needs to access the TextInput for this specific row
                  > whose
                  > btnBrowse has been clicked,
                  >
                  > // Called when the "Browse" button is clicked
                  > public function doBrowse( event:Event ):void
                  > {
                  > file.browse();
                  > var lb:mx.controls.listClasses.ListBaseContentHolder =
                  > event.target.parent.parent;
                  >
                  > if (lb==null) return;
                  >
                  > // This code doesn't work -- says:
                  > // TypeError: Error #1010: A term is undefined and has no properties.
                  > for (var i:int = 0; i < lb.numChildren; i++){
                  > var hb:HBox = lb.listItems [0] as HBox;
                  >
                  > if (hb==null) continue;
                  > var ti:TextInput = hb.getChildAt(1) as TextInput;
                  > if (ti==null) continue;
                  > ti.text = "hello world!";
                  > break;
                  > }
                  > }

                  Why go UP to the contentHolder and then back DOWN to the HBox that is the
                  parent of the thing that was clicked?

                  But I reiterate that if you use an itemClick event instead of a regular
                  click event, you will receive a different kind of event that has properties
                  specific to working with data.

                  HTH;

                  Amy


                  • 6. Strange behavior in Flex Builder 3
                    ac361 Level 1
                    Thanks, Amy. Now I'm able to update the TextInput; however, I've run into an issue where, after you've set the TextInput, if you scroll the datagrid, you'll notice (randomly) other TextInput fields in the same column with the same value. After some research, it appears to be that the itemRenderers are recycled -- only the first 10 or 12 rows have itemRenderers generated for them:


                    http://www.adobe.com/devnet/flex/articles/itemrenderers_pt1.html

                    http://blogs.adobe.com/aharui/2007/03/thinking_about_item_renderers_1.html


                    What a bummer. I can't write the filename the person selected to the dataprovider (the solution to the recycling issue) unless the user clicks the Upload button. One solution: Do a popup itemRenderer, where the only choices the user has are [Upload] and [Cancel]. This way we don't run into the issue.

                    I know it's a performance reason as to why itemRenderers are recycled; but I wish it were better documented. I almost lost my mind before I realized what was going on! Also, I wish there was a way to turn it off -- even if it means poor performance.