8 Replies Latest reply on Aug 6, 2013 11:35 AM by mfdezpo

    Recompiling framework.swc

    hubcin

      In order to solve the DPI problem (see my last topic),I decided to see the sdk source code.

       

      I found changing systemManager.as , DensityUtils.as ,  RuntimeDPIProvider.as and DPIClassification.as file is the key to my problem ,so I changed the classifyDPI method in RuntimgDPIProvider.as file :

       

      mx_internal static function classifyDPI(dpi:Number):Number

          {

              if (dpi < 200)

                  return DPIClassification.DPI_160;      

              if (dpi <= 280)

                  return DPIClassification.DPI_240;

      //   ↓↓    ↓↓  ↓↓ I changed  this ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

                if(dpi <= 360)

                   return DPIClassification.DPI_320;

       

                return DPIClassification.DPI_400;

          }

       

      then I added DPIClassification_DPI_400 = 400 in DPIClassification.as file

       

      In DensityUtils.as , I changed the getDPIScale method like this:

       

      public static function getDPIScale(sourceDPI:Number, targetDPI:Number):Number

          {

              // Unknown dpi returns NaN

              if ((sourceDPI != DPIClassification.DPI_160 && sourceDPI != DPIClassification.DPI_240 &&

        sourceDPI != DPIClassification.DPI_320 && sourceDPI != DPIClassification.DPI_400||

                  (targetDPI != DPIClassification.DPI_160 && targetDPI != DPIClassification.DPI_240 &&

        targetDPI != DPIClassification.DPI_320 && targetDPI != DPIClassification.DPI_400))

              {

                  return NaN;

              }

       

              return targetDPI / sourceDPI;

          }

       

      Now it seems that  I can handle DPI problem by changing all these files.

       

      BUT,there's a new problem, I have to recompile  framework.swc file to get these things work. If anyone have done this before?

       

      If these methods can be overrided in my application ,then how ?

        • 1. Re: Recompiling framework.swc
          Douglas McCarroll Level 1

          > If these methods can be overrided in my application ,then how ?

           

           

          Google this:

           

          ActionScript "Monkey Patch"

           

           

          Much easier than recompiling the Flex source. 

          • 2. Re: Recompiling framework.swc
            hubcin Level 1

            Thank you McCarroll ! It worked! I have already get it done ! hah

            • 3. Re: Recompiling framework.swc
              mfdezpo

              Hello, hubcin.

               

              I have the same problem than you, good although I see you've solved ...

              Can you give me specific instructions how i must to do?

               

              Thank you.

               

              Best Regards.

              • 4. Re: Recompiling framework.swc
                hubcin Level 1

                say, if you wanna change the current class  xxx.as in mx.core in framework.swc ,then just  add  a  new package mx->core in your src folder ,add a class exactly named xxx.as then edit that class to do whatever  you want . flex will read and execute your new class instead of the swc's when running. if you have problem making a new folder and class which has the same name as classes in swc's directly , try do it outside the flash builder. hope it will help .

                • 5. Re: Recompiling framework.swc
                  mfdezpo Level 1

                  Ok. First many Thanks for your patience.

                   

                  But I need to put all the code in SystemManager.as, and for the other: DensityUtils.as ,  RuntimeDPIProvider.as and DPIClassification.as and after make your corrections?

                   

                  Can yo send me by email this folder.

                   

                  I will be obliged greatly.

                   

                  Thank you again.

                  • 6. Re: Recompiling framework.swc
                    hubcin Level 1

                    QQ截图20130806233628.pngthis is my src folder. If you only need to solve DPI problem ,these will do.

                     

                    In DPIClassification.as ,I added two varieble:

                    public static const DPI_400:Number = 400;

                    public static const DPI_480:Number = 530; //480 is not enough in my app...

                     

                    In RuntimeDPIProvider:

                    if(tempDPI <= 360)

                        return DPIClassification.DPI_320;

                    if(tempDPI <= 440)

                        return DPIClassification.DPI_400;

                     

                      return DPIClassification.DPI_480;

                     

                    And then you have to change getDPIScale method in DensityUtil.as file to make them work:

                    public static function getDPIScale(sourceDPI:Number, targetDPI:Number):Number

                      {

                      // Unknown dpi returns NaN

                      if ((sourceDPI != DPIClassification.DPI_160 && sourceDPI != DPIClassification.DPI_240 &&

                        sourceDPI != DPIClassification.DPI_320 && sourceDPI != DPIClassification.DPI_400 &&

                        sourceDPI != DPIClassification.DPI_480) ||

                        (targetDPI != DPIClassification.DPI_160 && targetDPI != DPIClassification.DPI_240 &&

                        targetDPI != DPIClassification.DPI_320 && targetDPI != DPIClassification.DPI_400&&

                        targetDPI != DPIClassification.DPI_480))

                      {

                        return NaN;

                      }

                     

                      return targetDPI / sourceDPI;

                      }

                     

                    all you have to do is just telling the application.as to scale your app just as you want.

                    • 7. Re: Recompiling framework.swc
                      mfdezpo Level 1

                      Many, many Thanks.

                       

                      It works perfectly.

                       

                      Now I must to do all the modifcations in App (resources), but detection of DPI works correctly.

                       

                      Best Regards and Thank you again.

                      • 8. Re: Recompiling framework.swc
                        mfdezpo Level 1

                        There is another thing to do and is to modify MultiDPIBitmapSource.as inside spark/utils the same mode.

                         

                        Note: There is a small error in name of DensityUtils.as -> DensityUtil.as at the beginning of post.

                         

                        Thanks a lot again.