All Posts in AS3

December 11, 2010 - No Comments!

TypeError: Error #1006: value is not a function

A small issue that came up in my debugger today, where the following error was triggered by a Rich Text Editor.

TypeError: Error #1006: value is not a function.
at mx.controls::RichTextEditor/setComboSelection()
at mx.controls::RichTextEditor/getTextStyles()
at mx.controls::RichTextEditor/systemManager_mouseUpHandler()

The error is due to the way the font size drop down is set. We are able to set the values of the drop down via the following method.

richTextEditorInstance.fontSizeArray = [10, 20, 30];

However this format will create the error as the component is expecting a string based array, so to fix our issue we would declare our array as...

richTextEditorInstance.fontSizeArray = ["10", "20", "30"];

December 6, 2010 - No Comments!

Scale Bitmap with BitmapData and Matrix

Ran into small issue this morning where I needed to scale a bitmap. This was a shot of another movieclip, problem is if you scale the displayobject before taking your shot through bitmapData it doesn't scale the contents you are taking a shot of. In order to get round the issue we use the Matrix class... example code below.

Read more

October 18, 2010 - No Comments!

Available Font List AS3

Quick little tip for displaying the fonts you have loaded into your AS3 project. Once the fonts have registered run this small script to trace out the fonts available to your application.

var fontArray:Array = Font.enumerateFonts(false);
for(var i:int = 0; i < fontArray.length; i++) { var font:Font = fontArray[i]; trace(“name: “ + font.fontName); trace(“typeface: “ + font.fontStyle); }

June 13, 2010 - No Comments!

Unit Testing with Flash Builder and Flex Unit 4

Over the last couple of days I've had some time to look into a few features of Flash Builder, one of the exciting ones being the inclusion of unit testing. After having a quick look at online examples I was running into a few issues finding a complete example using Flex Unit 4 within Flash Builder, so here is a quick overview to get you up and running based on a mixture of examples I have been playing with.

We start by building a new flex project, >File >New >Flex Project. For this example I will just name it UnitTestDemo, keep the other settings as default (i.e. Application type: web, SDK:Flex 4), hit Finish. Now lets create a class we will perform our tests on. Here is my example class, named TestObject.

public class TestObject
public function TestObject()
public function returnNumberOne():int
return 1;
public function returnString(value:String):String
return value;
public function returnTrue():Boolean
return true;

This is just a simple class with a few example functions which we will run our tests on, ok... now for our test class. >File >New >Test Case Class. Create a name for your class, in this case I have named it as TestClass, Flash Builder will create folder to place these into named flexUnitTests.

Read more

June 7, 2010 - No Comments!

Posting to Social Media – An Actionscript Perspective

As more clients understand and appreciate the contribution social media has to the success of their projects, it is becoming ever more a standard for the projects I undertake to include some form of share functionality. Some of you are probably aware of the early issues faced with 3rd party APIs when using them within the Actionscript side of the project, as opposed to the javascript of the the holding page.

Lets start with the more simple side of things where users simply want to share a simple link.



Add to Any

Those are just some of the basics. For a slightly different scenario, how about we have created a project where the user wishes to share a custom status alongside an image for example. You will see examples of this in your "News Feed" of your Facebook Account where friends may have shared games scores which also contain a link to the game and a small thumbnail image to promote the game or application.

Read more

May 15, 2010 - 8 comments

VerifyError: Error #1014: Class mx.core::FontAsset could not be found

Just a quick issue I ran into today whilst trying to make use of runtime font loading inside Flash Builder. Where as before in Flex 3 it was a simple case of creating a class to construct a swf that would then be loaded in the main application. Today I ran into an Error #1014 - Class mx.core::FontAsset could not be found, when running the main application.

The fix as it seems is to add this to the compiler arguments of your font library swf.


Now if like me you use Ant Builder to compile your projects - simply add to your mxmlc tag within your ant script as shown here


Update: Adobe mention a fix to the noticeable file size increase. It appears that the increase is due to it including all classes that our "classes inherit from plus other framework dependencies" so we need to amend this script a little to something more like

mxmlc -runtime-shared-library-path=c:/p4/flex/flex/sdk/frameworks/libs/framework.swc, framework_3.0.183453.swz,,framework_3.0.183453.swf rsls/SimpleApp.mxml

For a more detail explanation check out Adobe's comments

May 7, 2010 - No Comments!

Memory Management in AS3 – A Quick Intro

As many of us know, memory management in any good size project is a topic that particular attention must be paid to. Over the last 12 months I have seen myself carrying out more and more research into memory management, in a recent project for example I was able to bring the memory usage of a website down by almost 30% in a matter of minutes by integrating simple techniques that I adopt in my own project builds.

In the words of Grant Skinner, "With great power comes great responsibility", and as we find ourselves building more complex applications it is important we consider  the internal Garbage Collector and help it carry out its chores. The understanding of the Garbage Collector is another topic in itself, this post is merely a few pointers which I use as a rule of thumb in my work flow.

General tips

  • Add an Event.REMOVED_FROM_STAGE listener to instance which calls in built function to tidy up assets for garbage collector
  • Use weak event listeners
  • Remove/ set to null any variables passed into the instance/ container
  • Set to null any strings contained by components e.g. label.text = null / image.src = null
  • Remove all children of the instance
  • Delete the instance i.e. delete this

Continued Reading