You would think that it would be fairly simple to include the Flex framework source code in a project, rather than using the framework.swc library. Simply include the [SDK]\frameworks\projects\framework\src folder in your source path and delete framework.swc from your library path, and you’re good to go, right? Well, it’s not quite that simple.

First of all, you also need to include the [SDK]\frameworks\projects\framework\assets folder, or you’ll get a lot of compile errors similar to this: “Invalid Embed directive in stylesheet – can’t resolve source ‘Embed(source = “Assets.swf”, symbol = “__brokenImage”)’”.

You’ll now be able to compile without any errors, but if you run your project it will throw this error – “TypeError: Error #1010: A term is undefined and has no properties.” – in StyleManagerImpl.initProtoChainRoots(). I’m not going to go into detail on why this occurs, but the root cause is that the compiler doesn’t find the default.css file in the [SDK]\frameworks\projects\framework folder. As a result the info() method in the generated* _[your_app's_name]_mx_managers_SystemManager file contains a line that looks like this:

mixins: [ "_ClassFactoryDemo_FlexInit", "_advancedDataGridStylesStyle", "_ClassFactoryDemoWatcherSetupUtil" ]

instead of like this:

mixins: [ "_ClassFactoryDemo_FlexInit", "_richTextEditorTextAreaStyleStyle", "_DividedBoxStyle", "_alertButtonStyleStyle", "_textAreaVScrollBarStyleStyle", "_headerDateTextStyle", "_globalStyle", "_ListBaseStyle", "_todayStyleStyle", "_windowStylesStyle", "_ApplicationStyle", "_ToolTipStyle", "_CursorManagerStyle", "_opaquePanelStyle", "_TextInputStyle", "_errorTipStyle", "_dateFieldPopupStyle", "_dataGridStylesStyle", "_DataGridStyle", "_popUpMenuStyle", "_headerDragProxyStyleStyle", "_activeTabStyleStyle", "_DragManagerStyle", "_ContainerStyle", "_windowStatusStyle", "_ScrollBarStyle", "_TextAreaStyle", "_swatchPanelTextFieldStyle", "_textAreaHScrollBarStyleStyle", "_plainStyle", "_activeButtonStyleStyle", "_advancedDataGridStylesStyle", "_comboDropdownStyle", "_ButtonStyle", "_HDividedBoxStyle", "_DataGridItemRendererStyle", "_weekDayStyleStyle", "_linkButtonStyleStyle", "_ClassFactoryDemoWatcherSetupUtil" ]

which is how it should look. In particular, the missing “_globalStyle” bit causes you app to break.

So you need to either include the [SDK]\frameworks\projects\framework folder in your source path, which will cause ‘overlapping source path’ warnings, or copy this file to another folder and include that folder in your source path. Personally, I just copy it into the [SDK]\frameworks\projects\framework\src folder, which accomplishes the same thing.

Now I know what you’re thinking. You’re thinking, “This is all wonderful, Douglas, but why would I want to do this in the first place? It works just fine to use framework.swc. Flex Builder sets up new projects so that this and other SWCs have a ‘source code attachment’. You can set breakpoints and step through the code, etc. Why do you need to actually compile the framework source code as part of your project?”

Well, in my case I’m doing this because, while all of that is true, it doesn’t seem that Eclipse’s ‘Mark Occurrences’ feature works with ‘source code attachments’. I rely heavily on this feature when I’m trying to figure out what code is doing, which is the whole purpose of this exercise in the first place.

But it seems as though there must be a simpler way to do this. If you know of one, please add a comment!

* If you aren’t familiar with generated code, try adding the ‘-keep’ option to your compiler options. Then recompile and look for a ‘generated’ folder your project’s main source folder. It will contain the ActionScript classes that are created based on your MXML files. These files are normally compiled into your project’s SWF then deleted. Turning on the -keep option simply tells the compiler not to delete them when it’s done with them.

3 Responses to “Using the Flex Framework source code in a project”

  1. TJ Downes Says:

    Hey Douglas, great post. Maybe you could do a post on the Mark Occurrences stuff. I would be interested in seeing how that works and how you use it.

  2. Brett Coffin Says:

    did you find an other way to get the mark occurences to work ?

  3. Douglas McCarroll Says:

    Brett – As far as I can see, the only way to get Mark Occurrences to work for code is to include it in the source path, as I did above. I’ve found no way to get it to work in ‘source code attachments’. If anyone knows of a way to do this, I’d *love* to hear it, as adding Flex 4 source has different challenges, which I haven’t worked through yet.

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word