7 Replies Latest reply on Apr 9, 2010 3:42 PM by davepmadison

    Flash Builder 4 unloadStyleDeclarations

    davepmadison

      Hi:

       

      I am working on an app that has 4 style sheets.  The style sheets are complied to .swf's.  I am doing an unloadStyleDeclartion on the style sheet in memory and then a loadStlyeDeclartion hooked into a changeHandler when selecting a style sheet from a drop down list.  Seemingly straight forward enough.

       

      The problem that I am running into is that the unload does not happen immediately but instead seems to be happening after a couple of events. I need the unload to happen before loading the selected style so that I don't need to have unnecessary style properties in all of my style sheets.  For some reason calling unloadStyleDeclartion does not seem to execute in the correct order or there is an unacceptable lag.  Does anyone have any suggestions?

       

      Here is the bit of code:

       

      protected function styleSelection_changeHandler(event:Event):void
                  {
                      if (styleSelection.selectedItem != null)
                      {
                          styleManager.unloadStyleDeclarations(appOptions.styleUrl, true);
                          styleManager.loadStyleDeclarations(styleSelection.selectedItem.data, true);   
                      }
                     
                  }

        • 1. Re: Flash Builder 4 unloadStyleDeclarations
          davepmadison Level 1

          So I am pretty new to Flex but this is really a deal breaker for me.  Can I provide more info on this problem?  Is this a bug? Does anyone have any suggestions as to how to fix this?  Is there something about using unloadStyleDeclaration and loadStyleDeclaration that I do not understand?  Any help would be greatly appreciated.

          • 2. Re: Flash Builder 4 unloadStyleDeclarations
            Flex harUI Adobe Employee

            How are you determining that the unload happened?

            • 3. Re: Flash Builder 4 unloadStyleDeclarations
              davepmadison Level 1

              Hi:

               

              Thanks for getting back to me late at night.  It is greatly appreciated.

               

              I am currently only verifying the unload through the console window in debug and of course visually.  I have set a font size in one of the four styles but not in the others in Global.  Although this behavior is not limited to things I set in Global.  I have seen this styling the s|droplist for example.

               

              It occured to me last night right before bed that I could hook in an event listener to check when the unload happens and when that returns then load the style.  This was the path that I though I was going to take this morning.  However after a bit of investigation I am getting further confused.

               

              I changed the code a bit just to test.  Here is what I have now.

               

              protected function styleSelection_changeHandler(event:Event):void
                          {
                              if (styleSelection.selectedItem != null)
                              {
                                  styleManager.unloadStyleDeclarations(appOptions.styleUrl, true);
                                     
                              }
                             
                          }
                         
                          /* styleManager.loadStyleDeclarations(styleSelection.selectedItem.data, true); */

               

              This is what it looks like on launch

              before.PNG

               

               

              This is after the unload apparently

              after.PNG

              So now I am really confused.  It appears as though the unload is attempting to happen but doesn't dump everything???

               

              Obviously I can just set the exact same style properties in all of my style sheets which wouldn't be that big of a deal if I didn't have to also assign a value to them to prevent this from happening.

               

              FWIW if I change this:

              if (styleSelection.selectedItem != null)

               

              to this:

              if(appOptions.styleUrl != null)

               

              it makes no difference.

              • 4. Re: Flash Builder 4 unloadStyleDeclarations
                Flex harUI Adobe Employee

                If you are looking for in the console it will happen during a

                garbagecollection pass long after the data has been unhooked from the

                StyleManager.

                • 5. Re: Flash Builder 4 unloadStyleDeclarations
                  davepmadison Level 1

                  Fair enough.  Although that doesnt explain what I am illustrating with my screen shots above.

                   

                  Looking at those it should be fairly clear that unloading is not happening cleanly. Some style properties are getting stuck when doing the unloadStyleDeclartions.  With my last code example I was trying to test what simply firing off the unloadStyleDeclartion was doing.  Obviously it is *at least in my case* not dumping all of the styles properties back to the defaults.

                   

                  Regardless can you point out something in the code sample that I may be doing wrong?  I mean it is a one line piece of code its not like there is any great compexity here.

                   

                  Can you give me any indication as to how I should *properly* be unloading style sheets compiled to .swf's?  That is really the crux of the issue. I dont have issue with the load.

                   

                  This worked in Beta 2 but stopped working after the release version was out.  I know a bunch of stuff changed WRT the style manager as I had to update all of my code for it to compile after release.

                  • 6. Re: Flash Builder 4 unloadStyleDeclarations
                    Flex harUI Adobe Employee

                    The main thing that changed after beta2 is per-module styles.  There is a

                    possibility you are unloading from the incorrect stylemanager or loading

                    into a parent stylemanager, or it could just be a bug.  Simplify your test

                    case as much as possible and open a bug.

                    • 7. Re: Flash Builder 4 unloadStyleDeclarations
                      davepmadison Level 1

                      Thank you sir.  I will do just that.