Flex

a shakey first few moments with 2.0.1

I had a scary first experience with the Flex Builder 2 (2.0.1) Trial on the Mac, after having commenced a project using the Beta…

Before installing, I was aware of the following bullet in the release notes

Opening old Flex projects – The Flex Builder 2.0.1 update cannot open projects that were created with pre-release versions of Flex Builder 2. Flex Builder 2 beta-level projects must be recreated in Flex Builder 2.0.1.

So I zipped a back-up copy of my project files.

On installing and launching 2.0.1, I was suprised that my existing projects seemed to open ok. But ‘cleaning’ the project had the effect of removing the html files. Additionally seemingly spurious errors were generated on compile. The first being 1023: Incompatible override.

I keep my project files on a seperate disc away from the default location. So I deleted the folder and restored just my source files from a zip and recreated the project in builder 2.0.1 – still no joy. In-fact even creating a new application project with only the default stub resulted in errors reported at lines which didn’t exist. (Similar to these reported issues on Flexcoders).

I found the issue to be primarily that the 2.0.1 Builder looks for the same workspace files as the Beta – and they aren’t compatible. The solution…

Rename the existing “Flex Builder 2” folder to “Flex Builder 2 Beta” to accurately reflect the builder that created it. (Just to ensure you can revert to using the Beta if you need to – which I thought would be a likely prospect if my experiment failed) On the Mac:

/Users/username/Documents/Flex Builder 2
becomes
/Users/username/Documents/Flex Builder 2 Beta

(Note: for Flex Builder 2 Beta to pick up it’s workspace again, you need to choose “File>Switch workspace…” from the menu. Not that you’ll want to go back to the beta, once you have 2.0.1 running properly.)

Then when launching the 2.0.1 version, the “Flex Builder 2” folder will be re-created but this time containing a 2.0.1 compatible workspace. You can then start creating projects, porting your old source files as you see fit.

All the spurious errors are now cleared, and proper html files created. So far looking good with improved performance over the beta!

Posted by creacog in Eclipse, Flex, Mac OS, 0 comments

New flex dot-one, one day away

In case you missed it we have a new Flex dot release (2.0.1) due in the next 24 hours. Very significant for us Mac users – time to get the full version and pay for it!

I was hoping that there might be a simultaneous Apollo release. But while this version introduces development support for Apollo, the beta version seems to have a way to go yet.

More detail of the new features here.

Anyway, “Ted On Flex” seems excited! (A blog worth signing-up to if you are interested in Flex)

Posted by creacog in Apollo, Flex, Mac OS, 0 comments

tile or repeat an image into a flex application background

UPDATE: There is a revised version of this post here, which you might find more accessible. It also includes a tile into the background of a Canvas.

I’ve only been using Flex for a few weeks via the Flex Builder Beta for the Mac. While I am really impressed with the ease of use of the framework, and now something of a convert, I was suprised by the apparent inability to tile (or repeat) an image over the background of the Application.

I tried a number of approaches which I now look back on as naive. I haven’t at this point managed to find a documented solution by googling. Though as responses to this post show (update: source now published), there seems to be interest in finding a solution.

So here is one solution. I don’t claim this to be ‘best practice’. Far from it. But it works, and will suffice for me until I am more familiar with Flex.

  1. Locate your flex installation, then Flex SDK 2/frameworks/source
  2. From here navigate the package structure to mx.skins.halo
  3. Duplicate file “ApplicationBackground.as” to a suitable location within your project file structure. In my case saved to ‘{projectroot}/com/ct/skins”
  4. Edit your local copy as per the following notes

Adjust the package detail

In my case the package line now reads:

package com.ct.skins

Add some imports

We need the following import lines to access the bitmap data:

import flash.display.Bitmap;
import flash.display.BitmapData;

Remove the version include

Because we are working outside the structure of the halo skin collection, we no-longer need or want the following line:
include "../../core/Version.as";

Embed the image and declare some variables

In this case I am embedding the image at compile time:

[ Embed( source='/assets/BackgroundLines.png' ) ]
private var backgroundImageClass :Class;
private var backgroundImage :Bitmap;
private var backgroundBitmapData :BitmapData;

Modify the constructor

In our constructor, after the call to ‘super()’ we need to get the bitmap data of the image into the backgroundBitmapData variable, we do this by first creating a Bitmap instance of the embedded image in backgroundImage, then drawing the data into backgroundBitmapData:

backgroundImage = new backgroundImageClass();
backgroundBitmapData
= new BitmapData( backgroundImage.width, backgroundImage.height );
backgroundBitmapData.draw( backgroundImage );

Clear out and replace the content of updateDisplayList

The only line we need keep is the super call. Everything else can be replaced with the following 4 lines:

var g:Graphics = graphics;
g.clear();
g.beginBitmapFill( backgroundBitmapData );
g.drawRect(0,0,w,h);

Now we just need to apply it.

All we need to do is point the borderSkin attribute of the mx:Application tag to this new skin. In my case the attributes of mx:Application look like this:

xmlns:mx ="http://www.adobe.com/2006/mxml"
frameRate ="36"
layout ="absolute"
borderSkin ="com.ct.skins.ApplicationBackground"

Bob’s your uncle!

I’d appreciate comments on a better practice approach.

Further reading:

Posted by creacog in ActionScript, Flex, Flex 2, 10 comments

cooking on flex


Added ActionScript 3.0 Cookbook to my reading list. Not strictly anything to do with flex but it’s saved me loads of time while learning Flex and I highly recommend it.

Posted by creacog in ActionScript, Flash Platform, Flex, 0 comments

Flexciting

It’s seemed like a longer wait than it was, but finally the Flex 2 Beta for Mac OS X is here. Posted on Adobe Labs on 23rd October.

Just in time for my next project which will be ActionScript 3 based and hopefully ready in time for Apollo. Flex seems like it will provide a better development environment than the Flash 9 Alpha.

Posted by creacog in ActionScript, Flex, Mac OS, 0 comments