Thursday, September 9, 2010

Frustrating Flex problems solved #6 - Keydown

Spent some time screaming "Why can't my component receive keyboard events? "

Crazy, I'm not sure why i never knew this, but for a component to receive keyboard events, it needs to implement IFocusMangerComponent. And then, however you're trying to receive keyboard events, by overriding keyDownHandler, or listening for a keydown event, it should now receive these events...

easy when you know how!

implements="mx.managers.IFocusManagerComponent"

Friday, September 3, 2010

Frustrating Flex problems solved #5 - ButtonBarButton bugs

So i had a series of custom Buttons all set up perfectly in a ButtonBar, when I realised that the design dictated that one of the buttons was a different size than was happening with the automatic sizing system...

So after discovering that the ButtonBar does not allow facility for resizing the width of a button, I had the choice. If i was going to extract the buttons from the ButtonBar, it probably would make sense to have them as a different type - Button for example. But reskinning my buttons as a different type could be time-consuming so I thought I'd see how I go just using ButtonBarButtons that aren't in a ButtonBar!

All turned out fine, except that my labels weren't appearing. A little delving into the code and I discovered the following code inside spark.components.supportClasses.ButtonBase:

// Push down to the part only if the label was explicitly set
if (_content !== undefined)
labelDisplay.text = label;


For my two cents, there's something strange going on there... So to set the label, I need to put the text inside the label property, and i need to ensure that content is not undefined. Set content to something arbitrary and the label appears! weird...

<s:ButtonBarButton label="Title" content="nada"/>

Thursday, April 8, 2010

XML read error in AIR

Back to blogging, working on a couple of projects:

I was importing an XML file using the standard technique of using a URLLoader, and in the result handler, setting the XML file with:
var result:XML = new XML(event.target.data);

But I found I had to move this to the FileStream class in an AIR application because the user had to specify the XML file to load. So I used:
var result:XML = new XML(stream.readUTFBytes(stream.bytesAvailable));

Suddenly I was getting a 1088 error on this line:
TypeError: Error #1088: The markup in the document following the root element must be well-formed.

After checking and rechecking the XML, I found that for some reason, there was a byte at the beginning of the byteString, which was causing havoc with reading the XML. So the String being returned by the readUTFBytes method had to truncate the first character. Like so:
var fileData:String = stream.readUTFBytes(stream.bytesAvailable);
var result:XML = new XML(fileData.substr(1));

Monday, November 16, 2009

latin flash tour

Went to the Latin Flash tour last week in Bogotá, and met Lee Brimelow. He went over and demonstrated some of the latest updates to Flash CS5 and the FlashPlayer 10.2.

Features that got my interest:

  • code snippets panel(frequently used code - similar to the old flash simple mode in old versions of Flash that people have complained about disappearing for years!)

  • code hinting(although I´ll probably keep using FlashDevelop)

  • FLA format is now an open format XML based file (with extension XFL) with all media external.

  • Font embedding panel - embedded fonts can be managed more easily

  • TLF text - a new text layout format which allows columns more easily(with editable text too!)

  • Multitouch event handling(if your hardware can handle it of course!)

  • Access to microphone data(turn your voice into darth vader apps coming up!)

  • Uncaught error event - Finally you don´t have to ensure you are catching every error possible to avoid the user ever getting a Flash uncaugh error message.

  • AIR - open a filetype with the default app

  • AIR - Filemanager API can now catch volume state change events(i.e. if the user plugs in a hard drive)

  • BUT of course! The feature that everyone talking and every question from the audience was about, was that Flash now has a feature to publish apps for the IPhone! No IPhone still doesn´t have a Flash Player, Flash packages for a native IPhone runtime. And the answer to almost every question about ´can the iphone apps do this´and ´can the iphone apps do that´was yes, it can do everything that the Flash player can do!(with the caveat that you just have to consider that performance might be worse on the Iphone)

Tuesday, November 3, 2009

Where in the world is Craig?


There´s been not much movement in this blog for a while because I´ve been travelling South America for a few months and am currently in Bogotá, Colombia. If by chance anyone in Bogotá is reading this, give me a shout. Would be very interested in meeting local Flash developers.

In other Flash news, I´m heading to the Adobe Latin Flash Tour next Friday with Lee Brimelow speaking, will post an update here afterwards.

Sunday, June 28, 2009

Embedded fonts disappearing when loaded into another SWF

I once found that when an AS3 flash movie(let's call it parent) that contained a UIComponent, loaded another AS3 flash movie(let's call it child) that contained a UIComponent with embedded fonts, the component within the child lost its embedded fonts.

I also discovered that if the parent contained the font, then the component in the child was then able to find the embedded font, and all was well.

However, this isn't an ideal situation, because I could imagine that you sometimes want the child movie to be able to operate independent of the parent, manage its own font embedding, or maybe not waste loading time of fonts in the main parent movie that may not even be required if the child isn't navigated to.

I was prompted to revisit this dilemma in a forum post, and it got me wondering what was going on. I can't find documentation to confirm, but I have a theory that once the parent has a UI Component it then tries to take over handling of the list of global Fonts that the child tries to access. This list of global Fonts maintained by the parent, doesn't by default have access to Fonts embedded in SWFs it loads.

However to give the parent access to the font, the child needs to register its font with the global list with:

Font.registerFont(ComicSans); //ComicSans for example

This ensures that when the parent takes over handling of the global list of fonts, it has access to the font the child has embedded.

Wednesday, May 20, 2009

Component styling utility function

In addition to an earlier post here:

I have put the sample code into a simple utility function that will apply a TextFormat style to any component or TextField, without needing to consider the specific syntax of the component.

You can download this here.