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,
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
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
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".
North America
Europe, Middle East and Africa
Asia Pacific