Facebook Flash app lessons…

Been building a few Facebook Flash apps lately, and learnt some lessons on the way, some that didn’t appear to be in manuals, or are easy to skip over and then find yourself problem-solving…

  • Your Flash object has to be set to wmode=transparent so that it plays nicely with z-indexes.
  • If you’re loading images from Facebook, you need to load a security policy file. eg:

Security.loadPolicyFile(“https://graph.facebook.com/crossdomain.xml”);

Tagged with:
Posted in Flash

SCORM with custom menu built in Flash

I’ve been researching into making a training course SCORM compliant. Been quite a learning curve, and to be honest the whole system seems quite outdated and excessively jargon rich. Reading the documentation is like trying to swim laps in a swamp…

ADL(responsible for SCORM) have built a javascript library(libscorm) that works with the latest version of SCORM(ironically called 2004), and can also be called from Flash.

I was tasked with the challenge of retaining the course as it was with a custom menu within Flash. I encountered problems trying to consolidate the idea of a custom menu within Flash with the concept of SCO’s.

There are ways described out there: (see here for a pure html solution) but there still seems to me to be less flexibility.

I was directed to the examples built by Philip Hutchison, which was an interesting take on the problem. He says in his blog:

In my opinion, SCORM only becomes difficult if you try and use it to handle a course’s sequencing and navigation, which even SCORM experts are hesitant to do (it’s considered a “broken” feature by many key figures in the industry).

What he is saying, and the elegant solution he proposed in a nutshell, was to build the system into just one SCO and use the perpetual data variable ‘suspend_data’ to record status information about modules within the course.

This works well, however there are some problems with his source:
1. It uses an old version of SCORM (1.2)

2. It uses a pipwerks javacript wrapper, which is great, but I fear as it’s a 3rd party product may not be maintained as new versions of SCORM come out, and may be more limited in functionality than the ADL developed LibScorm.

3. The Flash coding is a little strange(sorry Philip), using an include statement rather than an application class, something I haven’t seen since AS2.

So I took on the challenge to build a proof of concept example that addresses and resolves these three points. Download a zip file here that contains the source and SCORM ZIP package. It uses:

  1. SCORM 2004 Fourth edition
  2. the ADL developed javascript library LibScorm
Tagged with:
Posted in Flash

Video white

A recent task I had to achieve was to play a video for several seconds and extract a frame as a JPG several seconds in. I did not know the dimensions of the video ahead of time, so hoped to extract that information out of the video metadata, and create the video object at this point. Sounds simple enough!

However, this only seemed to work about 75% of the time. Occasionally I was seeing just white in certain videos, like they weren’t attached correctly to the Video object(despite receiving the metadata correctly). My theory was that perhaps the metadata was received after the FLV began playing, and that perhaps there can be problems creating a Video object and attaching a NetStream to it, after it has begun playing.

So I tried creating the Video object and then resizing after receiving the FLV metadata, but the resize seemed to have no effect when extracting the Bitmap Data. But finally found a solution – the Bitmap Data extracted correctly, if I placed the Video object inside a MovieClip and extracted the Bitmap Data of the MovieClip instead of the resized Video object.

Tagged with:
Posted in Flash

SharedObject not updating between tabs

Just created an app which required persistent data, so used a local SharedObject. However discovered that if one person had the app open in two different places(eg. 2 tabs) the persistent data in one tab wasn’t updating in the other tab. To remedy this I tried reloading the SharedObject(SharedObject.getLocal) every time I extracted a variable, and yet this SharedObject variable still wasn’t updating.

Discovered that, strangely, the only way to update the SharedObject, is to first set it to null. Set it to null and then reload it forces an update.

Tagged with:
Posted in Flash

Frustrating Flex problems solved #7 – Removing DragDrop animation

In Flex was building a simple drag and drop from a library list to another simple list. I also wanted to build the functionality of dragging the item out of the simple list to automatically remove the item from the list, and return the item to the library.

I managed to handle this with one problem remaining. As the dragged item thought it wasn’t going to be accepted, it automatically played an animation of it returning to the simple list before my code displayed it back in the library. The animation was completely misleading but I couldn’t find a way to turn it off!

My solution in the end was to create a custom ListItemDragProxy component. I included this in the list with:
dragIndicatorClass=”display.CustomListItemDragProxy”

and in the custom class, I merely set visible=0 onMouseUp. Simple solution that works perfectly.

Tagged with:
Posted in Flex

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”

Tagged with:
Posted in Flex

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”/>

Tagged with: ,
Posted in Flex

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));

Tagged with: ,
Posted in AIR, Flash

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)
Posted in Flash

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.
Posted in Flash