Skip navigation
stevemcl5
Currently Being Moderated

How do I patch Flex code?

Apr 10, 2012 3:38 PM

Tags: #flex #building #patching

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,

 
Replies
  • Currently Being Moderated
    Apr 10, 2012 4:47 PM   in reply to stevemcl5

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 11, 2012 9:18 AM   in reply to GordonSmith

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

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 11, 2012 10:30 AM   in reply to Zolotoj

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 25, 2013 11:49 AM   in reply to stevemcl5

    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".

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 23, 2013 8:33 PM   in reply to GordonSmith

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 23, 2013 9:30 PM   in reply to thx1138

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 25, 2013 7:22 AM   in reply to stevemcl5

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

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 25, 2013 8:22 PM   in reply to Flex harUI

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

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 25, 2013 8:23 PM   in reply to KishoreModuga

    Kishore,

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

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 29, 2013 11:49 PM   in reply to Flex harUI

    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".

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points