15 Replies Latest reply on May 7, 2009 6:03 PM by Michael Borbor

    Standard Events in Custom Control?

    Miggl Level 1

      I have a custom control based on a LIST object, which contains a custom ITEMRENDERER.

      I wanted to utilize the itemClick event that comes with the List control, but when I click on an item in the list it doesn't fire. Do I need to do something specific to make use of standard list events if I use an itemrenderer, and if so, what do I need to do?

       

      Thanks!

      Mike

        • 1. Re: Standard Events in Custom Control?
          Gregory Lafrance Level 6

          The controls in the itemRenderer will fire whatever controls they normally fire, so a Button control in the renderer will fire a click event.

           

          Can you just use the click event?

          1 person found this helpful
          • 2. Re: Standard Events in Custom Control?
            Miggl Level 1

            The controls I have in the itemRenderer have no click events (they are labels and images). So that means that the default itemClick event that belongs to the list doesn't get fired, precisely because I have a custom itemRenderer?

            • 3. Re: Standard Events in Custom Control?
              ntsiii Level 3

              What does your extended List do?  Typically subclassing preserves the functionality of the base class.  Are you calling "super" in the constructor?

               

              Tracy

              • 4. Re: Standard Events in Custom Control?
                Miggl Level 1

                Here is my custom control:

                 

                <?xml version="1.0" encoding="utf-8"?>
                <mx:List 
                     xmlns:mx="http://www.adobe.com/2006/mxml"
                >
                     <mx:Script>
                          <![CDATA[
                               import mx.controls.Image;
                               
                               [Bindable]
                               public var subLabelFunction     :Function;
                               [Bindable]
                               public var subLabelField     :String;
                               [Bindable]
                               public var imageFunction     :Function;
                               [Bindable]
                               public var imageField          :String;
                               [Bindable]
                               public var imageWidth          :String;
                               [Bindable]
                               public var imageHeight          :String;
                          ]]>
                     </mx:Script>
                     <mx:itemRenderer>
                          <mx:Component>
                               <mx:HBox>
                                    <mx:Image
                                         source="{this.parent.parent.imageFunction(data)}"
                                         height="{this.parent.parent.imageHeight}"
                                         width="{this.parent.parent.imageWidth}"
                                         scaleContent="true"
                                    />
                                    <mx:VBox>
                                         <mx:Label
                                              text="{this.parent.parent.labelFunction(data)}"
                                              height="15"
                                         />
                                         <mx:Label
                                              text="{this.parent.parent.subLabelFunction(data)}"
                                              height="15"
                                         />
                                    </mx:VBox>
                               </mx:HBox>
                          </mx:Component>
                     </mx:itemRenderer>     
                </mx:List>
                

                 

                I haven't intentionally overwritten anything on the base class. Did I do something inadvertently?

                • 5. Re: Standard Events in Custom Control?
                  ntsiii Level 3

                  That is pretty odd looking.  What are you trying to do?

                   

                  Why are you declaring public properties, then reaching to the component's parent chain to get the values?

                   

                  Does this actually work, except for the itemClick issue?

                   

                  Tracy

                  • 6. Re: Standard Events in Custom Control?
                    Miggl Level 1

                    Sure, it renders exactly how I need it to.

                     

                    I need to use the parent accessors to get to the public properties defined at the component scope, since the itemrenderer components are at a lower scope.

                     

                    How would you do it? (Keep in mind that I'm learning as I go and trying my best to get things working as I need them to.)

                     

                    Thanks,

                    Mike

                    • 7. Re: Standard Events in Custom Control?
                      ntsiii Level 3

                      Try "outerDocument" instead of the parent chain.

                       

                      But still, what are you trying to do?

                       

                      Tracy

                      • 8. Re: Standard Events in Custom Control?
                        Miggl Level 1

                        I have attached a screenshot of the list in action. All I want is to be able to make use of the itemClick event (that is part of the list base class) and call a method to handle the click.

                         

                        So, in my app I have this:

                             <mx:Script>
                                  <![CDATA[
                                       private function listItemClicked(event:ListEvent):void
                                       {
                                            Alert.show("test");
                                       }
                                  ]]>
                             </mx:Script>
                         <composite:DetailedIconList
                                                 id="l_items"
                                                 dataProvider="{this._displayItems}"
                                                 labelFunction="showListLabel"
                                                 subLabelFunction="showListSubLabel"
                                                 imageFunction="showListImage"
                                                 imageHeight="35"
                                                 imageWidth="35"
                                                 width="100%"
                                                 height="100%"
                                                 itemClick="listItemClicked(event)"
                                            />
                        
                        

                         

                        Note that this is just the relevant portion of the code.

                         

                        Now, my problem is that clicking on an item does not trigger an alert box, as I would have expected.

                        • 9. Re: Standard Events in Custom Control?
                          ntsiii Level 3

                          I mean, what are you tring to do by extending List, instead of using the base List with a custom item renderer?

                           

                          Tracy

                          • 10. Re: Standard Events in Custom Control?
                            Miggl Level 1

                            Sorry, not sure I understand: I am using a normal list with a custom item renderer, only that I'm packaging it in a custom component for re-use. Due you see an inherent drawback to that?

                             

                            Thanks,

                            Mike

                            • 11. Re: Standard Events in Custom Control?
                              ntsiii Level 3

                              So you are extending List to provide some static properties that you are feeding to a hard-coded custom itemrenderer, is that accurate?

                               

                              No, no inherent drawbacks(except code complexity, but that is our job as developers!), I am just trying to understand your goal.

                               

                              What happens if you remove the customItem renderer?  Do you get the itemClick then?

                               

                              Tracy

                              1 person found this helpful
                              • 12. Re: Standard Events in Custom Control?
                                Miggl Level 1

                                My apologies everyone!

                                 

                                It turns out that the click event was working after all. Clearing the browser cache fixed it. Grrr ... hate those type of things.

                                 

                                Anyway, I appreciate all your efforts!

                                 

                                Thanks!

                                Mike

                                • 13. Re: Standard Events in Custom Control?
                                  Michael Borbor Level 4

                                  That's really annoying, please close the thread.

                                  • 14. Re: Standard Events in Custom Control?
                                    Miggl Level 1

                                    I thought I had done that. Well, anyway, here goes again **closing thread**.

                                     

                                    (I think that closing a thread by editing a previous post is bugged. I had it not take a few times now.)

                                    • 15. Re: Standard Events in Custom Control?
                                      Michael Borbor Level 4

                                      If you think that there's room for improvement with this forum, speak up my friend. The Adobe fellows surely will help.