FileReference woes on MACs

Today I found out (the hard way) that there are several issues that can occur when trying to upload files using the FileReference class on MACs.

FileReference.type always returns null

It’s often that case that you want to restrict the file type the user can upload, or perform different processes depending on the type of file uploaded. However the type property of a FileReference object always returns null on MACs; to work around this you must get the file extension manually. To do this you can use the following code (it’s good practice to always convert the file extension to lower case before working with it).
Continue reading »

Posted by Mark on February 17th, 2010
 

Clipboard Management using the StatefulToolkit

Tutorial Overview

This tutorial will build upon the Introduction to using the StatefulToolkit example; it will add the ability to utilize the Clipboard in our example. The example will use the ClipboardUtil, which is a utility class included in the toolkit that allows the user to copy and paste objects using the clipboard. The example application will build upon the last one; it will allow the user to position four circles, to save and load the state of the circles (i.e. where the circles are positioned) and to copy and paste the circles. The example can be seen here and source files are available.

Preparation

Before you being implementing this tutorial make sure you have the latest version of the StatefulToolkit SWC, and that you’re project is set to target Flash Player 10 (if you want to target FP9, simple replace the Vector with an array in the circle container) . This tutorial also uses Keith Peter’s Minimal Comps component set to create the buttons in the application so you may want to grab the SWC for that too, but you can use your own buttons if you prefer. Both SWC files are included in the available flex project.
Continue reading »

Posted by Mark on February 16th, 2010
 

New Year(ish), New Look

I’ve always wanted to create my own WordPress theme for my site, but haven’t had the time (or patience!) before. I was hoping to have it complete by the new year but it took a back seat whilst I worked on the StatefulToolkit. Over the past week I’ve had chance to implement the design, and here it is! I hope you like it.

Now to get back to the StatefulToolkit…

Posted by Mark on February 14th, 2010
 

Introduction to using the StatefulToolkit

Tutorial Overview

In this tutorial I’ll take you through the basic premise behind the StatefulToolkit and demonstrate how it can be used in a project. If you haven’t heard of StatefulToolkit before then be sure to read up on it. This example will also demonstrate use of the FileUtil, which is a utility class included in the toolkit that allows the user to load and save states. The application is very basic and will allow the user to position four circles and to save and load the state of the circles (i.e. where the circles are positioned). The example can be seen here and source files are available.

Preparation

Before you being implementing this tutorial make sure you have the latest version of the StatefulToolkit SWC, and that you’re project is set to target Flash Player 10 (if you want to target FP9, simple replace the Vector with an array in the circle container) . This tutorial also uses Keith Peter’s Minimal Comps component set to create the buttons in the application so you may want to grab the SWC for that too, but you can use your own buttons if you prefer.
Continue reading »

Posted by Mark on January 24th, 2010
 

StatefulToolkit for AS3 (Beta)

Update: Don’t forget to take a look at the Introduction to using StatefulToolkit.

What is it?

The StatefulToolkit was developed to enable the simple management of states in AS3. At the heart of the toolkit is one interface called IStatable. Any object that requires the retrieval or setting of its state must implement this interface. The toolkit comes with utility classes to help carry out some of the basic tasks associated with state management.

What’s included in the beta?

The initial 0.1 beta release includes the interfaces to implement and two utility classes, one to aid in saving and loading states and another to enable clipboard management, so you can copy and paste objects.

The utility classes are both currently optimized for the Flash Player – that’s not to say they can’t be used in the AIR runtime (they’d work perfectly fine) but they take into account the security sandbox restrictions that are found in the Flash Player. For example, the FileUtil allows you to save and load states, but does this using the FileReference class whereas in an AIR application you may want this to be done silently (without the browse box appearing), which would use the File class.

Continue reading »

Posted by Mark on January 24th, 2010
 

Happy New Year!

OK, so it ‘s a couple of days late but I’m now back at work and in the swing of things so I thought I’d write a new post.

2009 was a good year for me, I started my full-time job at MMT Digital after finishing university and have really started to delve a lot deeper into programming. The last year has seen me really improve my understanding of OOP as well as use design patterns and frameworks in my daily work.

This year, my new years (programming) resolutions are to:

  • Finish the Flash game I started programming in Autumn 2009
  • Pull together and publically release my stateful toolkit (AS3)
  • Learn more about TDD (test driven development) and optimisation
  • Blog more
  • and finally, play!

I’m hoping that by posting my resolutions I’ll actually stick to them, especially the top two – I’d really like to seem them out in the wild. I’d also like to blog more, even if it’s just some of the random things I come up with when playing with code!

I hope you all have a successful and enjoyable 2010!

Posted by Mark on January 5th, 2010
 

SWFObject not embedding Flash in Firefox

Whilst working on a site that used SWFObject to add Flash to a page, I came across a situation where my Flash movie wouldn’t embed in Firefox, but it would in all the other browsers. Here’s an code excerpt from the page.

1
2
3
4
5
6
7
<script type="text/javascript">
   swfobject.embedSWF("myContent.swf", "myContent", "300", "120", "9.0.0");
</script>
 
<div id="myContent">
   <p>Alternative content</p>
</div>

After spending around an hour on extensive research (Google!) and checking the case of my code, I still couldn’t find a solution to the problem.

Eventually I discovered that Firefox executes JavaScript at a different time to other browsers. Other browsers appear to load the page and then execute the JavaScript on the page, whereas Firefox appears to execute the JavaScript when it gets to it.  So by moving the script to below the div it miraculously worked in Firefox. It would probably be better if the embedSWF function was called on document ready. You can see the corrected code below. It’s so simple when you know how!

1
2
3
4
5
6
7
<div id="myContent">
   <p>Alternative content</p>
</div>
 
<script type="text/javascript">
   swfobject.embedSWF("myContent.swf", "myContent", "300", "120", "9.0.0");
</script>
Posted by Mark on November 20th, 2009
 

What’s all the HYPE about?

Branden Hall and Joshua Davis have collaborated on a new framework called HYPE. Their aim with HYPE is to help bring back the playfulness that once defined the Flash community.

What's All The Hype About?

Getting Started

The HYPE framework lowers the barrier for people to begin playing with Flash by offering a lot of functionality out-of-the-box. It’s really easy to get started with HYPE, just download the framework from the homepage. They’ve even put together a nice set of installation and setup instructions, which shows you everything from how to install the files to adding basic functionality. Branden has also posted a Halloween themed tutorial screencast that shows how to use some of the core functionality of HYPE.

Continue reading »

Posted by Mark on November 1st, 2009
 

Flash on the Beach 09 Write Up

OK, so it’s a little late but I thought it was worth sharing my experience of Flash on the Beach this year.

Flash on the Beach 09

We all know about Flash CS5, codenamed ‘Viper’, and it’s many new features so I won’t bang on about that. Although I am looking forward to having custom code hinting, and the ability to publish to multiple devices (inc. the iPhone). Instead, I thought I’d list the sessions I attended and my thoughts on them.

iPhone Application Development for Flash Developers

On the Sunday I was able to attend the iPhone workshop with Julian Dolce, which was really good! Julian covered the basics of Objective-C, including displaying external images, playing sounds and using the UI Kit. It hasn’t made me want to shell out for a Mac and begin a career as an iPhone developer, but it was a brilliant insight into how it all works, and I left feeling confident that I could build iPhone applications (if I wanted to).

Adobe Keynote

Although Adobe had MAX coming up, it was nice that they gave FOTB attendees some sneak peaks at CS5. In the keynote Richard Galvan talked about Flash Player penetration figures, the future of Flash on Mobiles, upcoming features in Adobe AIR and showed sneak peaks of CS5. The announcement that interested me the most was the ability to deploy Actionscript 3 Flash applications to Mobiles using Flash Player 10.1; I think it’ll be awesome to use the same codebase to deploy to multiple devices (and it’ll be great to completely eradicate the need for AS2!).
Continue reading »

Posted by Mark on October 25th, 2009
 

Code Formatting for Flex Builder 3

Recently I’ve been introduced to a code formatter for Flex Builder 3 and thought it was worth sharing. The plug-in formats, indents and rearranges both MXML and ActionScript code.

Code Formatting for Flex Builder 3

Downloading the plug-in

There is a version of the plug-in available here, but I haven’t installed it from there. Below I’ve included instructions on how to install the plug-in using the software updates feature in Flex Builder. Continue reading »

Posted by Mark on September 10th, 2009