Adobe

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

flash webservices pending call gotcha – well got me for a while

I have a webservice running from asp.net. Sample method interface…

[WebMethod( Description = "Returns the About content" )]
public XmlDocument getAbout()
{
  xmlDoc.LoadXml( "<about></about>" );
  rootElement = xmlDoc.DocumentElement;
/*
* add some child nodes... etc
*/
...
  return xmlDoc;
}

As you can see the return type is of XmlDocument.

In ActionScript I am using code within a class similar to…

  private var myPCO :mx.services.PendingCall;
  private var myWSO :mx.services.WebService;

// myWSO is intialised once in a constructor or some other suitable location
  myWSO = new WebService( "/TheService.asmx?WSDL" );

//inside some function we initiate the data load
  myPCO = myWSO.getAbout();
  myPCO.onResult = mx.utils.Delegate.create( this, pcoResult )

// we handle a dataresult...
  private function pcoResult( result:XML ):Void
  {
    trace( result.firstChild.nodeName );
  }

The trace returns ‘undefined’. Spotted the mistake?

Because my service is returning an XML object, I assumed the ‘result’ would be the XML object. It isn’t. It is simply an object which contains the XML object, the root node of which you can access directly by name. In this case…

private function pcoResult( result:Object ):Void
{
  trace( result.about.nodeName );
}

This now correctly traces ‘about’.

Posted by creacog in ActionScript, Flash Platform, 1 comment

reading list

Commenced creation of my reading list of books and online references I have found useful. Initially concentrating on the Flash and ActionScript books I used to get involved in this technology.

Posted by creacog in ActionScript, Flash Platform, User Groups, 0 comments

mac flash switch

I recently had the need to be able to switch player versions on the mac, and was very grateful to have found Mike Chambers‘ “Flash Player Switching on Mac” entry. Following the instructions in that entry may well be all you need. Be sure to read comments IV and V – they are important!

In my own set up I made a couple minor alterations to ease things in my own mind (to be read in conjunction with Mike’s article)…

  1. With respect to setting up the ‘soft-link’ or alias to “Internet Plug-Ins” I find an alias name of “InternetPlug-Ins” less likely to cause confusion than the more generic “plugins”. (Norton utils for example creates a “Plug-ins” folder within /Library)
  2. Similarly to avoid any confusion within the InternetPlug-Ins folder which in my case contains loads of files, I created a sub-folder “flashplayers” into which I placed the version folders.

So my resulting folder/file structure is as follows…

/Library/InternetPlug-Ins/
  Flash Player Enabler.plugin
  Flash Player.plugin
  flashplayer.xpt
/Library/InternetPlug-Ins/flashplayers/7
  Flash Player Enabler.plugin
  Flash Player.plugin
  flashplayer.xpt
/Library/InternetPlug-Ins/flashplayers/8
  Flash Player Enabler.plugin
  Flash Player.plugin
  flashplayer.xpt
/Library/InternetPlug-Ins/flashplayers/9
  Flash Player Enabler.plugin
  Flash Player.plugin
  flashplayer.xpt

The idea being that the three files currently in /Library/InternetPlug-Ins represent the currently active version of the player.

As my folder structure is different to that of Mike’s, my script is slightly modified…

#!/bin/bash
#
# Script to change the flash player
#
if [ $# != 1 ]; then
  echo "Usage: $0 name-of-player-version-dir"
  exit
else
  plugin_dir='/Library/InternetPlug-Ins'
  np_dir="$plugin_dir/flashplayers/$1"
  if [ ! -d $np_dir ]; then
    echo "$np_dir does not exist."
    exit
  fi
  cp -rv $np_dir/* $plugin_dir/
fi

Finally if you are not familiar with writing and running scripts via the terminal, two things to bear in mind…

  1. Placing your script file in a folder picked up by the path, will ensure it is available to you whatever is your current working directory. In my case I use the default tcsh shell and cfp is placed in my /Users/username/bin directory. This is added to the path in my via my .tcshrc file with the line
    setenv PATH "$PATH":bin
  2. Make sure you set the executable flag on the script file:
    chmod +x cfp
Posted by creacog in Flash Platform, Mac OS, 2 comments

embedding flash in html page – best practice? (SWFObject)

For a long time I simply used the html published from the Flash IDE to embed a SWF. Expecting that to be the ‘best practice’ approach. Like others I was concerned at the impact of Microsoft’s upcoming changes to IE in response to EOLAS patent issues. I was dreading either having to write my own JavaSript or research countless approaches.

With SWFObject the problem is solved. It has been around for a long time (formerly known as FlashObject) and appears to be well tried and tested. I was really pleased with how simple it is to use, how it degrades gracefully. I’ve used this on a number of projects and now consider it to be best practice. In future I’d need a very good reason not to use it.

Update (14/03/2008): SWFObject 2 released

Posted by creacog in Flash Platform, Javascript, XHTML/CSS, 2 comments

make my h1 look nice

I’ve recently been distracted from my flash ambitions back to the world xhtm/css design. One of the issue with the organisation concerned is that in print media they use what I think is a really nice font: ITC Century Light. Ideally this is what should be used for all h1 headers through this site. Obviously not many users are likely to have this font installed. The substitute font is Times New Roman which is not nearly as neat, or distinctive.

In the bad-old days we would have created GIFs for each heading and used them instead. The height of bad-practice in this new world of standards compliance and accessibility.

Prior to doing any research, I had expected use of Flash would fall foul of similar problems. Then I found sIFR. A combination of JavaScript, CSS and Flash, which at run-time replaces designated tags with a SWF containing the text rendered in your font of choice to the same dimensions. What’s better it ticks most of the accessibility boxes. I’m really pleased with how easy this was to set up, and how it gracefully degrades.

Ok I came to this late. But the current version (2.02 at time of writing) has been recently updated with bug fixes and changes relating to ELOAS. And there is a version 3 in development.

This is a good piece of work by the developers, who are looking for funding. Certainly if my client goes with this recommendation, I’ll be sending a donation.

Posted by creacog in Accessibility, Flash Platform, Javascript, XHTML/CSS, 0 comments