Notes: Migrating from Flex 3 to Flex 4
These are notes from Adobe MAX 2009. This session will help us see what problems we may encounter moving to Flex 4, as well as what new features we can use.
Packages. The old mx packages are still there. But now everything new is in the spark packages. Why two different packages? At first, they had them all in the same package, but the component had a prefix for the new version. It wasn’t received well. So instead, Adobe just put the new components in new namespaces.
The MX namespace is also called “Halo”. Don’t consider it a “legacy” namespace. These are still fully supported. Spark is all of the new stuff. The general MXML has a new 2009 namespace, but the legacy namespace is still supported.
Graphics
You can add graphic primitives enabling you to draw lines, ellipses, and curves, directly within the MXML. With the new FXG file format, you can import a graphic in as a vector graphic that appears as code. Cool. Using a static FXG image is great for icons or other static simple images, because its rendering is faster than an MXML graphic container.
Flex States
Instead of using AddChild and RemoveChild for changing states, you have includeIn=”" and excludeIn=”" attributes that go directly on components. What’s more, you can set various attributes of a component for the different states by using a dot notation. For instance, title.mystate=”Title”. This seems like a pretty drastic change.
With states, you have to use the OLD way with the 2006 namespace, and you have to use the NEW way with the 2009 namespace.
Skinning
Components all have separate skin files. This will allow you to create a custom skin for any component easily.
Common migration issues
Type selectors need namespaces now in your Flex CSS. For instance, if you’re styling a button, Flex doesn’t know if it is a Spark button or a Halo button. So you need to define the namespace in your stylesheet and update your selectors accordingly.
You must compile against Flash Player 10. This won’t be an issue if you use Flash Builder 4 with Flex 4.
Application.application should now be renamed to FlexGlobals.topLevelApplication. Just a direct rename.
RSLs are on by default.
The “Declarations” tag is a problem child. In Flex 4, anything that is not a display object or default property must be within the fx:Declarations tag. Even tags like RadioButtonGroup. Formatters, Effects, RPC stuff, Validators, etc. need to go in the Declarations.
“If Looks Could Kill.” The default theme is now Spark, which looks different than the old Halo theme. You can switch back to the Halo theme. To do so, turn on “Use Flex 3 compatibility mode” in the project properties, or go into the “Flex Theme” panel and change the theme (this is the preferred way).
If moving to Flex 4, try to use as many Spark components as you can. They should play nicely with MX components. You can intermix them together. Caveats: (1) The graphic primitives cannot go in an MX component, just wrap them with a group; (2) you cannot put MX components in Spark containers; (3) MX effects do not work on Spark graphic primitives; (4) MX navigators (ViewStack, Accordion, etc) should use NavigatorContent component.
Other things to watch out for:
- Spark components don’t support the Halo theme.
- Cannot create spark component based itemRenderers for MX List based components
- APIs between MX and Spark components are different (e.g. addChild vs. addElement)!
- When using MX and Spark components together, you may see a text difference since they are themed differently. There is a TLFText theme that can help with this.
So, migrating an app from Flex 3 to Flex 4 is a bit of a slippery slope. And even just beginning to use Flex 4 with current Flex 3 knowledge will require a bit of a slowdown as you undo some of those brain synapses to do things the new Flex 4 way. But these changes going forward are good for the Flex framework.

October 17th, 2009 at 9:51 am
[...] 来源页面: http://blog.crankybit.com/notes-migrating-from-flex-3-to-flex-4/ [...]
January 15th, 2010 at 12:55 pm
Sucks. FB3 stays in my heart!
January 15th, 2010 at 1:46 pm
I understand. I haven’t moved to Flex 4 yet myself, except when I’m just playing around and testing things out.
March 24th, 2010 at 2:05 pm
If this was all, I would consider upgrading, but there must be more. Just spent hours adjusting styles etc., my application is still dead … Strange thing is, I tried several times earlier – with Beta Releases – and there were no Problems … No good, I don’t want to spend hours on an upgrade, if hours are those things I try to save using Flex in the first place …
May 7th, 2010 at 4:17 am
Its just … a nightmare ! Is there a tools to do it automatically ?? Why they have changed everything ….
May 9th, 2010 at 3:02 pm
It’s as much of a nightmare as converting from Flex 1.5 to Flex 2. Apparently Adobe still hasn’t managed to get their $hit together.
June 25th, 2010 at 3:29 am
flex 4 or FB4 is such a waste of time, trying to dig money from developers/designers to use their Flash Catalyst (another waste of time). Flex3 is already a great framework and needs some little improvement but not like changing it whole face. Hope the Flash builder 4 developement die soon and turn back the good old flex3.
July 8th, 2010 at 3:52 pm
Flex seems to be a grand experiment for a rotating group of programmers on overhead is my guess. Flex is a frustrating moving target. It seems they are learning more about object oriented design on each new release? I’m waiting for Flex 5 Devil Dog UI components that make your Halo and Spark stuff obselete.