10 Replies Latest reply: Jun 29, 2013 11:49 PM by thx1138 RSS

    How do I patch Flex code?

    stevemcl5 Community Member

      How do I patch Flex code?

      I want to patch ..\sdks\4.6.0\frameworks\projects\spark\components\Scroller.as

      the file is read only, what's the procedure to edit it? 
      Do I edit it as an administrator?  and will my project pick it up? 
      or can I copy it to my project and how do I tell my project to pick it up?

      thanks,

        • 1. Re: How do I patch Flex code?
          GordonSmith Adobe Employee

          Use "monkey patching": Put an edited copy of Scroller.as at spark/components/Scroller.as within your source-path directory. (If your source-path specifies multiple directories, you can use any one.) The compiler will then see two classes named spark.component.Scroller, one coming from a SWC file (the original in spark.swc) and one coming from an AS file (your monkey-patch file). The AS one will take precedence over the SWC one.

           

          Gordon Smith, Adobe

          • 2. Re: How do I patch Flex code?
            Zolotoj Community Member

            Nope, I did it and it still uses the one from SDK.

            • 3. Re: How do I patch Flex code?
              GordonSmith Adobe Employee

              I just tried it and it worked for me. I created a Flex Project called "Monkey" in Flash Builder 4.6. I created an "mx" package and a "core" package in the project Then I used New > ActiionScript File to create a UIComponent.as file in the mx.core package. (Note: If you try to use New > ActionScript Class, Flash Builder won't let you because it knows there is already a class named mx.core.UIComponent.) I entered the following code in my version of UIComponent:

               

              package mx.core

              {

                  import flash.display.Spriet;

               

                  public class UIComponent extends Sprite

                  {

                  }

              }

               

              Then I cleaned the project (this could be important!) and built it. I got some expected errors because my monkey-patched version of UIComponent is an empty extension of Sprite:

               

              Description Resource Path Location Type

              Cannot resolve attribute 'minHeight' for component type spark.components.Application. Monkey.mxml /Monkey/src line 4 Flex Problem

              Cannot resolve attribute 'minWidth' for component type spark.components.Application. Monkey.mxml /Monkey/src line 4 Flex Problem

               

              Gordon Smith, Adobe

              • 4. Re: How do I patch Flex code?
                thx1138 Community Member

                If you have a library and a project that uses it then it will not recognize your patches (if classes in them use them) unless you put the patch in both projects. This causes problems in that when you modify one you have to modify the other. It also causes null exception errors in Flash Builder sometimes.

                 

                One way to solve this is to create a new Flex library called MySDKPatches. Add the patches there. Then in your project library and the project that uses the project library add a source path to the src directory that contains the patched classes.

                 

                In Flash Builder this is at Project Properties > Flex Build Path > Source Path > Add Folder and then point to your directory that has classes, such as, "${DOCUMENTS}/MyFlexSDKPatchs/src".

                • 5. Re: How do I patch Flex code?
                  thx1138 Community Member

                  I used the above method and it works when I view it with the content debugger but if I view it on another computer with the release player (or use Chromes built in release player on my computer) the project never finishes loading. It stalls here,

                   

                  Screen Shot 2013-06-11 at 11.50.31 PM.png

                  • 6. Re: How do I patch Flex code?
                    Flex harUI Adobe Employee

                    Are you saying that when you hit the same URL from the content debugger that it works?  Often we hear that someone tests locally with the content debugger, then when deployed to a server and hit from the release player it gets stuck, usually because some RSL or other asset is not available.

                    • 7. Re: How do I patch Flex code?
                      KishoreModuga Community Member

                      Better one is override which method you want to add the code to scroller.as.

                      • 8. Re: How do I patch Flex code?
                        thx1138 Community Member

                        That's correct. I've set merged into code for the project so there are no RSL's.

                        • 9. Re: How do I patch Flex code?
                          thx1138 Community Member

                          Kishore,

                          I'm patching FlexSprite so I can't do that.

                          • 10. Re: How do I patch Flex code?
                            thx1138 Community Member

                            After some modification it appears to be working. Here is what I've changed:

                             

                             

                             

                            FlexSDKPatchLibrary

                            This project contains my patched classes.

                             

                            In Flex Library Compiler > Additional compiler arguments I have, "-locale en_US -link-report=linkreport.txt -include-inheritance-dependencies-only". The linkreport.txt may not be needed.

                             

                            In Build Path > Classes I chose the option, "Select all classes to include in the Library" and then manually selected the classes.

                             

                            In Build Path > Library Path I set the Framework Linkage to Merge into code.

                             

                            MyLibrary

                            This project contains classes used in the main project.

                             

                            In Flex Library Build Path > Source Path I've added a reference to "${DOCUMENTS}/FlexSDKPatchLibrary/src".

                             

                            In Build Path > Library Path I set the Framework Linkage to Merge into code.

                             

                            MainProject

                            This is the main project that uses classes from MyLibrary.

                             

                            In Flex Build Path > Library Path I set the Framework Linkage to Merge into code.

                             

                            In Flex Build Path > Build Path Libraries MyLibrary is added as a project (Add Project > Select Library).

                             

                            In Flex Library Build Path > Source Path I've removed a reference to "${DOCUMENTS}/FlexSDKPatchLibrary/src".