6 Replies Latest reply on Dec 4, 2009 6:39 PM by mewk

    Is this a bug or am I doing something wrong? (Custom Buttons)

    cdman522 Level 1

      I have a project where I've created a custom buttonbase which has a custom skin.

      Create a button that uses the custom skin which extends the custom button base the first time the button is used it doesn't work the way I would expect.

      Here's what happens. The first time the app is loaded the button's up state shows up just fine. If I mouse over the button it flashes black for a second while it loads the mouse over state. If I mouse out and over again it works normally. Now if I click on the button it flashes black again while it loads the selected state and then the selected over state. After the first time the button functions correctly. But naturally I don't want the button to flash black the first time it's used. I want it to show my custom skin the first time not the second and subsequent times.

       

      I've included a project that demonstrates the problem. I have added some for loops in the part of the code that determines the custom colors for the button, just so that the black flash is really obvious.

       

      If you look at it there are three classes. The ButtonSkinBase which defines the base look for all skinned buttons. The ButtonSkin which is a specific skin to use. And the ButtonGraphic which is just a custom definition for a button.

       

      I think the problem is in the SDK in that it isn't loading the ButtonGraphics in the ButtonSkinBase class before they are used. It loads them when they are used. However, I'm not that experienced with the way the SDK functions under the covers so it could be that I'm not doing something I need to do.

       

      Any help with this would be great.

      Thanks,

      cdman

        • 1. Re: Is this a bug or am I doing something wrong? (Custom Buttons)
          Flex harUI Adobe Employee

          I don't have time to look at your project right now, but if you are loading external data like SWFs or PNGs you can have this problem as the content is ready until the next frame at the earliest.  You'll need to calculate or guess at the final size.

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          • 2. Re: Is this a bug or am I doing something wrong? (Custom Buttons)
            cdman522 Level 1

            That's a good point, but I'm just changing the colors. No images are involved.

             

            cdman52

            • 3. Re: Is this a bug or am I doing something wrong? (Custom Buttons)
              mewk Level 3

              When you use the includeIn command, by default the object will only be created when it is needed. Hence, you will execute a creationComplete event, and therefore atleast 100 million (sometimes 400 million) loops, when each required Button state is needed. Obviously, once each button state has been created the creationComplete handler (invalidateDisplayList) will not usually be called again.

               

              As written, bioStyleChanged will always remain true

               

               

              if(!bioStyleChanged) {
                bioStyleChanged = false;
              }     
              

               

               

              this code does nothing for you.

               

              - e

              • 4. Re: Is this a bug or am I doing something wrong? (Custom Buttons)
                cdman522 Level 1

                >When you use the includeIn command, by default the object will only be created when it is needed. Hence, you will execute a creationComplete

                >event, and therefore atleast 100 million (sometimes 400 million) loops, when each required Button state is needed. Obviously, once each button

                >state has been created the creationComplete handler (invalidateDisplayList) will not usually be called again.

                 

                So are you saying there is a better way or another way to do that? Or are you just telling me that's how it works? Because I know that the includeIn isn't creating the other buttons untill they are needed. I need them created when the button is created. That is my question, how do I get the other states to be created when the button is created so that I don't see the button flash black?

                 

                 

                 

                 

                 

                >As written, bioStyleChanged will always remain true

                >if(!bioStyleChanged) {

                >       bioStyleChanged = false;

                >}    

                 

                >this code does nothing for you.

                 

                 

                Sorry, I missed that when cleaning up the code to ask for help.

                Thanks,

                cdman52

                • 5. Re: Is this a bug or am I doing something wrong? (Custom Buttons)
                  David_F57 Level 5

                  hi,

                   

                  Checkout itemCreationPolicy property if you want forward instantiation of components.

                   

                  David.

                  1 person found this helpful
                  • 6. Re: Is this a bug or am I doing something wrong? (Custom Buttons)
                    mewk Level 3

                    Well, if you don't want to see flicker -- and you insist on running up to 400 million loop iterations -- then, yes, I would think you would need to run these in the beginning.

                     

                    I would do away with overriding invalidateDisplayList -- you should only override this if you need changes sometime during RT (also the guard should be some change flag -- not the existence of some skin part).

                     

                    Instead, we have several options: we could use creationComplete on the entire button, we could encapsulate the methods in the button's createChildren() method, or we can use the new spark component life cycle. I have tried the latter option, and attached the project to this message.

                     

                    Hopefully, this approach will work for the greater needs of your app. Best o luck,

                     

                    - e