Using Google Maps within CS3

A friend of mine asked me if I knew a way to get google maps working within CS3. At the moment google made this flex only. If you’ve carefully read my previous articles you already know the drill.

This is what you need to do to get it working within CS3:
1. download the sdk from: http://code.google.com/apis/maps/documentation/flash/
2. copy the google swc to the flexsdk/frameworks/libs folder, where the other swc’s reside
3. create a library.as (read my previous article) from the HelloWorld google example and compile an swf and swc from that
4. run HelloWorld.as within your CS3 IDE

Download my example here to see it in action!

Good luck!

Intrinsic Library maker for Flash CS3

Jesse Warden had a post about the new Gaia Beta framework created by his friend Steven Sacks. In his post he commented and talked about my library solution. Let’s quote him:

There are just certain audiences that totally agree with what your doing, and others who are like, “That’s too much trouble”. We need to satiate those peeps. Yes, compiling a separate library is hard; it’s an extra step. If you make this shiz easy for Flash peeps, it rocks. Stay tuned…

To be honest, in the end I totally agree with what he says. So I sat down with my colleague Paul and we came up with a solution that automates the process of creating this ‘intrinsic’ library, in the form of a panel within Flash CS3!

Here are the screenshots that do all the talking:

Libmaker general configuration   Libmaker project configuration

This is the first version, it has no Apple support just yet. In the next version I promiss we’ll add Apple support and an auto import feature my other colleagues came up with.

To make the install as easy as possible we’ve created an mxp. So for now, download version 0.0.1 here.

Using Flex compiled code within Flash!

Why did I put effort in combining Flash and Flex generated swf’s?

A major AS 3.0 obstacle for me is the fact that the flex RPC sources are not available. This means we can only use rpc.swc supplied within the Flex framework or use a third party library. Another big thing I’ve been messing around with is the idea of using cairngorm within the Flash authoring environment. As we all know cairngorm depends heavily on databinding, one can simulate databinding using simple macros and a preprocessor or one can let the flex compiler do all the hard work and embed the flex generated library into flash. I’ve been trying hard and succeeded in both, just read on…

As I was messing around with flex (compc) generated swc’s and things like playerglobal.swc, flex.swc, rpc.swc, etc… I came to found out that Flash actually compiles code against swc’s!! Yes, that’s compiling, this means NO linking! So, the linking part has to be done manually… Do you remember ‘intrinsic classes’ back in the good old AS 2.0 days? This result is the same, but you’re not dealing with exclusion xml’s and or the ASI files!
In short, what do you need to do?:

  1. First create a class that will import your needed dependencies (mx.*, whatever you need!)
  2. Now create your component library from your class file with ‘compc’, for ex:
    ‘compc -source-path . -include-classes FooLib -output=./example.swc’
    You should now have an swc file which you can use to compile against. In the flash authoring environment the swc is only used for type checking, think of it as an intrinsic package!
  3. Now you’ll compile the library that you’ll dynamically load to access your classes:
    mxmlc -source-path . -o ./bin/library.swf ./FooLib.as
  4. Before you’re ready to compile against your newly created library you need to load the library at runtime. As far as I can tell there are two options, my favorite is to link against it as a shared library. This allows all your swf’s to run quickly without any actual code! First you make a link to the library and when you’re done you put the movieclip on the first frame of your application. The other option (which is excellent as a preloader btw.) is to use a standard flash.display.Loader. (Just don’t forget to set the ApplicationDomain in the loadercontext or you’re classes will not be accessible!)
  5. And finally you’re ready to compile your Flash classes against the classes flex compiled for you.

As a proof of concept I’ve converted (read quick & dirty) the cairngorm cafetownsend mxml views to Flash. The views have dependencies on cairngorm and the flex framework (mx.rpc.*, mx.validators.StringValidator, etc..), but they compile without any of these classes in the path just because the swc sits besides the fla! You can download this package here. After you’ve downloaded the flex sdk to your favorite location you need to run ‘compile.cmd’ (put the flex sdk ‘bin’ folder to your path, or you need to edit compile.cmd and at the path in front of compc and mxmlc), this will automate step 2 & 3. Now you can open cafetownsend.fla and compile without any errors.

If you’re only interested in getting webservices support in Flash then download the examples here.

Now let’s use cairngorm within our Flash authoring environment :-)

For ‘Jon Bradley’ from the FlashCoders maillist I tested some flex controls. And yes, that’s possible as well although you need some style classes initialized before adding controls to your view. My first attempt involved custom flex initialization, download that one here. My second attempt has a better workflow: you create a basic flex application which is compiled against your library.swc. This basic flex application is used for initialization when you want it to! The trick involves the overriding of the flex application. If you want to look into this method further then download a working example here.

As far as I (or google) can tell this is the first proper solution to use your flex classes within Flash!

[Edit1]As Geoff van den Ouden found out, this solution does not work instantly with the Flex 3 SDK! You need to add “-compute-digest=false” to as an extra parameter to compc. Or you should download flex 2.0.2.[/Edit1]

[Edit2]Julian Kussman got AIR crashing while using this method. It turns out AIR doesn’t like the shared library option. You can download a working AIR rpc example here.[/Edit2]

Good luck!