Can Flash 9 preview compile the Flex Framework?

Update: I’ve learned that there’s no easy way to use the Flex Framework without MXML. It may be possible, but probably very difficult. See the comments below for more information.

Maybe I’m just doing this all wrong, but I had the urge to see if I could use the Flex Framework within the new Flash Professional 9 Actionscript 3 Preview, and I ran into some troubles. First of all, it looks like SWC components are completely disabled for Actionscript 3 projects. Luckily, the free Flex 2 SDK comes with it’s source code. I added the path to these files to my class path, and I set the new Document Class parameter to mx.core.Application. I’ve added no additional code to the timeline. When I try to compile, I get a weird error:

**Error** C:\Program Files\Adobe\Flex Framework\frameworks\source\mx\core\Container.as : Line 15, Column 1 : [Compiler] Error #1004: Namespace was not found or is not a compile-time constant.
import flash.display.InteractiveObject;

This same error at the same line in the same file is repeated several times. I find it especially odd that the compiler can’t seem to recognize flash.display.InteractiveObject since that’s one of Flash’s built-in classes. The error list ends with one last error:

ReferenceError: Error #1065: Variable Application is not defined.

No line numbers, just the single line. I assume that one appeared because Container is a dependency to Application.

Can anyone tell me if Flash should even be able to compile the framework? I know that there’s a lot of meta information in those classes. Maybe Flash doesn’t understand some of it. Now, I don’t actually need to compile it within Flash, it was just an interesting little experiment. I’m such a geek.

About Josh Tynjala

Josh Tynjala is a frontend developer, open source contributor, bowler hat enthusiast, and karaoke addict. You might be familiar with his project, Feathers UI, an open source user interface library for Starling Framework that is included in the Adobe Gaming SDK.

Discussion

  1. JesterXL

    Flash doesn’t understand MXML. Furthermore, mxmlc has some special jazz to work with the framework, I’m sure.

    Still, there’s gotta be SOME stuff that’d compile… not sure. Anyway, good luck!

  2. Josh Tynjala

    Jesse,

    The base framework components themselves are all Actionscript, not MXML. If you look in Flex 2 SDK\frameworks\source, you can see all the code. I actually figured Flash would choke on the styles, but it’s very strange that the errors came from importing flash.display.InteractiveObject.

  3. Firdosh Tangri

    how about trying this. Make a simple empty mxml file
    and when compiling make sure to have

    –keep-generated-actionscript

    turned on and then add the generated .as files to the classpath.

    Just an idea 🙂

    cheers 🙂
    firdosh

  4. Josh Tynjala

    Firdosh,

    That’s a good idea, but I’m not talking about using custom MXML components. The Flex 2 SDK comes with the Actionscript source code for all of it’s built-in components, such as Button, List, Tree, etc. I want to compile that code within the Flash 9 preview. I would have used the SWCs, but Flash seems to disable the component picker when working with an AS3 project.

    Or maybe you meant that I should make an MXML application so that I’m not working with the Application class directly? That’s certainly something I could try. I’ll keep you updated.

  5. Daniel Hai

    I’m having the same sort of problems — it looks like it’s not even possible — browsing through the alpha directory under “Flash 9 Public Alpha\en\Configuration\ActionScript 3.0” — The playerglobal.abc and global.abc files are formatted completely differently then that of the imported swc’s.

    Looks like we’ll have to wait and see if Adobe gives us a framework.abc and a flex.abc file.

    I tried even pointing the class path to the source directory in the framework, but no luck (even though classpath seems to work with my custom classpaths)

    very strange indeed.

  6. Daniel Larsen

    I have been playing with this same idea for a few days, but alas, I have not been able to figure anything out.

    They have all of the new components written in as3 code. You would THINK there would be SOME way to get this to work. I have tried all of the above before I found this post as well. Nothing seems to fully work.

    Anyone able to shed some light? In the final BLAZE release, will we have all of the components that have been included in the flex framework? if not…..WHY NOT?!

  7. Josh Tynjala

    On the Flashcoders mailing list, Mike Chambers from Adobe answers my question:

    There is not support for using the Flex Framework in an AS only project. While it is theoretically possible, you would have to manually bootstrap a lot of the application initialization code that Flex handles (something which would be rather complex).

    Source: Flashcoders.

  8. Fuad Kamal

    Man this just SUCKS. Flash 9 preview doesn’t come with ANY components and you can’t make use of the Flex component architecture – not even a simple TextArea control can be instiated from AS. I got the same compiler errors. So basically if you wanted to develop anything slightly usable you’d have to create all your own components in Flash or port the AS2 component architecture to AS3. What a waste…for someone who spent all his time developing in Flash IDE prior to Flex 2, it would’ve been nice to be able to utilize the F9 Preview for more than some theoretical code experiments.

  9. julien

    The thing is, Flash != Flex 🙂 I’ve been using the free sdk for a bit more than a month now, a bit different at first but much more “developer” friendly. If i could, i’d never switch back to the Flash IDE.

    Cheers

  10. Andrew Csizmadia

    Hello!

    Just for testing purposes I want to compile an Application+FlashCS3 Component-Framework with Flex MXMLC, so perfectly the reverse side than what this article is about.
    My problem is that i got type errors like:
    D:\SVN_CVS\FLASH\classes_as3_flex\fl\managers\StyleManager.as(97): c
    ol: 39 Warning: return value for function ‘getInstance’ has no type declaration.
    Has anyone experience in this? Should I continue the testing or I had to port the application to the flex component framework to compile with succes?

    Regards
    Andrew

  11. Josh Tynjala

    Andrew, it is possible to use the Flash CS3 components with MXMLC, but you’ll have to work a little magic. The warning you posted is nothing to worry about. It’s just a warning. However, when you try to run the project, you may discover runtime errors related to the StyleManager and other things of that nature. The Flash CS3 components are designed to be FLA-based. They’re supposed to have skins in the library of a FLA, but you can do one of two things:

    1. Create all new skins programmatically and update the StyleManager (the fl.* one, not the mx.* one) to point to those skins. Might be bit of work, though.

    2. You should be able to export any Flash CS3 component from the library as a SWC fo;e and use it in ActionScript with MXMLC. The skins are already associated with the component at that point, and they should be included in the SWF. (If you aren’t aware, you can right-click on a component and choose Export SWC…)

  12. Andrew Csizmadia

    Thanks for the response, it really works.
    I’ve done some experiences porting flex framework to flash, and had to say it could be succeed, but not the whole part.
    For example the mx.graphics classes can be easily ported to flash cs3 compatible, and many other util and helper classes also.
    What is the most impossible, is porting code what is related to the flex ui component framework, but in that case, you can grab the api/interface, and re-create it to flash compatible, but Adobe style..
    For example i created a flash compatible drag-drop manager where the basic idea come from the air and flex drag-drop manager api.
    I think the importance is in Adobe style, because i like the api’s what their programmer create, and in this way i’m more sure that my framework will be as4 compatible or like that.
    At the end, i’m still not concerned about, that is it optimal that all the flex related classes are useless in flash, until you port the code to compatible, in my ideal world i can work with flash or flex on the same project, or related classes, not just with assets. Now its just halfly true, if true.