5 Replies Latest reply on Jul 22, 2016 11:26 AM by numsgil

    How to force updatedisplaylist in a skin when custom property changes

    D Baron Level 1

      Hi Folks,

       

      I have created a custom component based on a Spark Button.  In that custom component I have added a single, public, bindable property - let's call it Fred.

       

      I also have a custom skin, based on the Spark Button skin.  It's basically just like the delivered skin, just a bit different graphics stuff.  I have applied the custom skin to the custom button component.  So far, so good.  However...

       

      When a user action causes the Fred property to change on a custom button instance, I need my custom skin to re-draw something.  It appears that I need the skin's updateDisplayList function to fire.  Unfortunately, it appears that the only time that it fires is when "real" properties are changed, like 'left' or 'width'.  How can I get the custom skin to updateDisplayList when this fake, custom property changes?

       

      p.s. - the custom skin can 'read' the custom Fred property just fine.  And, if I set the Fred property and then 'mouse over' the custom button instance, the updateDisplayList fires...too late of course, but it does fire.

       

      I have read the docs, but there is not much written about updateDisplayList, or when it fires, or how to make it fire.

       

      Thanks,

       

      -David

        • 1. Re: How to force updatedisplaylist in a skin when custom property changes
          Wrataxas Level 2

          The reference to Fred in the skin needs to be part of something that causes drawing.  Like if you had the width of a Rect set to {hostComponent.Fred} then the change would propagate to cause drawing.  How are you using Fred in your skin?

          • 2. Re: How to force updatedisplaylist in a skin when custom property changes
            D Baron Level 1

            Good question...in my skin's 'creationComplete' event I call a function in the skin.  That function 'evaluates' the host component's Fred propertey, and based on what it finds, it draws some stuff:

            protected function doSpecialDrawing():void

            {

                 var hostFred:String = hostComponent.Fred;

                 if (hostFred == "certain_value")

                      //set some property in one of the path objects in my skin to a certain value

                 else if (hostFred == "other_value")

                      //set some property in one of the path objects in my skin to some other value

            }

             

            When I created the skin, I did not anticipate the need to dynamically respond to setting the Fred property/value.

             

            I've placed a call to the 'doSpecialDrawing' function inside the skin's updateDisplayList, but unfortunately, the updateDisplayList does not seem to get called in real-time when I set the Fred property in a custom button instance.

             

            I'm all ears here... still a beginner/novice with Flex...

             

            Thanks,

             

            -David

            • 3. Re: How to force updatedisplaylist in a skin when custom property changes
              Wrataxas Level 2

              One way I can think of is that when you change Fred in the component, you could also call skin.invalidateDisplayList() at the same time.

               

              Or you could have the skin listen for an event that the component dispatches and trigger an invalidateDisplayList() off of that.

               

              Perhaps a nicer way is to use the data binding you have set up already.  Fred gets updated in the skin by an event being sent to it.  If you could have a listener for that event, you could get the display list redrawn from there.  I don't know how to do that though.

              • 4. Re: How to force updatedisplaylist in a skin when custom property changes
                D Baron Level 1

                You got it on the first line...  when I set the 'custom component's Fred property, I then call that button instance's .skin.invalidateDisplayList() and boom, it works like a charm!

                 

                I thought I tried this before, but obviously not.

                 

                Thanks man (or girl?),

                 

                -David

                • 5. Re: How to force updatedisplaylist in a skin when custom property changes
                  numsgil Level 1

                  Thanks from me too, I spent a lot of time calling invalidateDisplayList on the hostComponent, instead of the skin, and scratching my head when it didn't work.