Outlook 2010: Auto BCC yourself (works with multiple accounts)

Because I check my pop-based email from multiple devices (main computer, phone and tablet), I BCC my outgoing emails to myself.  This means that they are received into the inbox on all of my devices, and I always have a record of my sent mail on each device (as well as received mail).  I also select the Outlook option NOT to place a copy in the ‘sent items’ folder, so that I don’t double-up.

I use the following VBA script to achieve the automatic BCC – note that I am NOT an expert in VBA or in Outlook, and have cobbled this together from a couple of examples. I’ve seen several stack overflows and other threads saying that the sender is not available until after the Application_ItemSend process is complete, so theoretically this script/macro shouldn’t work.  However, this macro seems to work no problem for me – I think perhaps the call to ‘Resolve’ is the key here?

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim objRecip As Recipient
    On Error Resume Next

    Set objRecip = Item.Recipients.Add(Item.SendUsingAccount)
    objRecip.Type = olBCC
    Set objRecip = Nothing
End Sub

Note that there is no error checking in this script. It assumes that the sender (SendUsingAccount) exists and that it is a valid email address.

Good luck!

#1 – If this doesn’t work for you, here is an alternative way where the BCC email address is manually specified in the script. Also take a look at this article for detailed instructions on how and where to add the macro, if you’ve never added one before.

#2 – If you need to self-sign your macro to get it to work (which is likely), follow these instructions.

Non-tile-based 2D path finding. Part 1

I took some time out to experiment with path finding for a (secret) game I’ve been planning for some time.  Loosely, it’s a 2D platformer with tap-to-move controls.

What I achieved

Before I let on what or how I did it, here is what I achieved so far:

  • Code builds a non-tile based path (navmesh) automatically from the map
  • Determines the closest walkable point to the mouse when clicked

What I did

These are the parameters for these first set of tests:

  • 2D platform map
  • Click on any point for the character to move there (if she can)
  • Character must move along walkable surfaces
  • Character can’t jump (that will probably change later)
  • Non-tile based. Can be any shape or size
  • In Adobe AIR/AS3

I decided to go for a node-based approach.

  • The map is made up of nodes
  • Each node connects to one or more other nodes
  • The character can only move in a straight line between nodes
  • Nodes can be any distance, and any angle apart (e.g. slopes)
  • The character can travel to any point between nodes (doesn’t have to stop exactly on node)

Here is a simple illustration:

  • Character starts on Node A
  • Player taps close somewhere between B and C
  • Game calculates closest point to the tap on the exact line segment between B and C
  • Character moves along nodes until it reaches the destination
  • Player then taps close to Node E
  • Game calculates closest point to the tap on a line segment, which happens to be on Node E
  • Character moves back to Node B which has a connection to Node D, and through to Node E
  • Character does NOT move directly to Node D*

* Note that in the future, with jumping for example, something like this may be possible. But not for now.


How I did it

Storing the path

The path is stored as a vector (list) of nodes. Each node has a position, some other stuff (that will be important later), and a vector of ‘joins’. Each join is a reference to a connecting node, along with some data to describe the connection (also important later).

Using the example above, the node data may look something like this:

  • A. x=76, y=186
    • B
  • B, x=205, y=172
    • A
    • C
    • D
  • C, x=310, y=237
    • B
  • D, x=226, y=326
    • B
    • E
  • E, x=115, y=310
    • D

Notice that each node has a join back to the previous one too (a join each way). So A links to B, but B also links separately back to A. This is because I want to be able to do one-way paths in the future.

Creating the path

Skip to calculating closest point if you are just interested in the path finding. This next bit is really just an aside, and is very specific to AS3.

I drew the path in the Flash IDE just using the line drawing tool.  I exported the path as a MovieClip symbol so that my code could access it.  The code then uses graphics.readGraphicsData and steps through the vectors to pull out the path. Here are the important bits:

// ### In Main
// Create an instance of my symbol that contains the lines/path
var clip : MyExportedVectorPath = new MyExportedVectorPath();
// Create a path object (the object that does all the heavy lifting)
path = new Path();
// Pass in the lines so that the code can rip the nodes/joins
path.buildFromClip( clip );

// ### In Path.buildFromClip
// ### ... this is just a snippet ...
// Grab all the graphics data from the symbol instance
var graphicsData : Vector.<IGraphicsData> = clip.graphics.readGraphicsData(true);
// Step through the graphics data
for (var i : int = 0; i < graphicsData.length; i++) {
    // If we have found a path (i.e. a line or series of lines)...
    if (graphicsData[i] is GraphicsPath) { 
        var path : GraphicsPath = GraphicsPath(graphicsData[i]);
        // Step through all the commands that make up the line(s)
        for (var j : int = 0; j < path.commands.length; j++) {
            // If the command is 'MoveTo' then we are creating a new node somewhere without creating a join
            if (path.commands[j] == GraphicsPathCommand.MOVE_TO) {
                // Handle creating a new node, or grab the node
                // at this location if it already exists
            // If the command is 'LineTo' then we are creating a join between two nodes
            else if (path.commands[j] == GraphicsPathCommand.LINE_TO) {
                // Handle creating a join to another node. It'll
                // either be a new node or an existing one at this
                // location

Calculating the closest point

This is the first part of the actual path finding. In my implementation, the user taps on the screen (or clicks with the mouse) and the closest walkable point to the tap is found.  This is done like this:

  1. Iterate all line segments (joins) in the map. Because each join is usually there twice (A to B, and B back to A) make sure you do each one only once
  2. Find the closest line segment to the tap
  3. Find the point on the closest line segment that is closest to the tap

Here are the methods I use (I have them in a class called GeometryUtils).  They are three relatively simple and related methods that I sourced elsewhere on the net, starting from this stack overflow.

 * Calculates the distance from a point to the closest point on a line segment. TIP: If comparing
 * distances between more than one line segment and a point and you don't need to know the actual
 * distance, use relativeDistFromPointToLineSegment instead (faster).
 * @param	segA	First point on line segment
 * @param	segB	Second point on line segment
 * @param	p		The point
 * @return			The distance to the closest point on the line segment
public static function distFromPointToLineSegment( segA : Point, segB : Point, p : Point ) : Number{
	var dp : Point = new Point(segB.x - segA.x, segB.y - segA.y);
	var something : Number = dp.x*dp.x + dp.y*dp.y;
	var u : Number = ((p.x - segA.x) * dp.x + (p.y - segA.y) * dp.y) / something;

	if (u > 1) u = 1;
	else if (u < 0) u = 0;

	var dx : Number = (segA.x + u * dp.x) - p.x;
	var dy : Number = (segA.y + u * dp.y) - p.y;

	return Math.sqrt(dx*dx + dy*dy);

 * Calculates a weight (not an actual distance, just a representative number) between a point an the
 * clostest point on a line segment. This is used to compare lots of line segments with a point and
 * determine which is the closest.
 * TIP: If you need the actual distance, use 
 * @param	segA	First point on line segment
 * @param	segB	Second point on line segment
 * @param	p		The point
 * @return			A value representing relative distance from the closest point on the line segment
public static function relativeDistFromPointToLineSegment( segA : Point, segB : Point, p : Point ) : Number{
	var dp : Point = new Point(segB.x - segA.x, segB.y - segA.y);
	var something : Number = dp.x*dp.x + dp.y*dp.y;
	var u : Number = ((p.x - segA.x) * dp.x + (p.y - segA.y) * dp.y) / something;

	if (u > 1) u = 1;
	else if (u < 0) u = 0;

	var dx : Number = (segA.x + u * dp.x) - p.x;
	var dy : Number = (segA.y + u * dp.y) - p.y;

	return dx*dx + dy*dy;

 * Returns the point on a line segment that is closest to a given point.
 * @param	segA	First point on line segment
 * @param	segB	Second point on line segment
 * @param	p		The point
 * @return			The point on the line segment closest to the given point
public static function closestPointOnLineSegment( segA : Point, segB : Point, p : Point ) : Point{
	var dp : Point = new Point(segB.x - segA.x, segB.y - segA.y);
	if ((dp.x == 0) && (dp.y == 0)) return segA.clone();
	var something : Number = dp.x*dp.x + dp.y*dp.y;
	var u : Number = ((p.x - segA.x) * dp.x + (p.y - segA.y) * dp.y) / something;

	if (u > 1) return segB.clone();
	else if (u < 0) return segA.clone();

	return new Point( segA.x + u * dp.x, segA.y + u * dp.y );

If you read the comments in the code you’ll notice that you can use distFromPointToLineSegment or relativeDistFromPointToLineSegment.  The first returns the actual distance and is used if you need the exact distance. The second actually returns the square of the distance (leaves out the square root for speed) which is ok because we don’t actually care what the distance is, as long as we can compare it to the other line segments.

So my code does something like this:

// Iterate all nodes
for each (node in nodes){
    // Skip nodes that have been checked, then flag this one as checked
    if (node.checked) continue;
    node.checked = true;

    // Iterate all line segments coming off this node
    for each (join in node.joins){
        // Calculate distance to tap (Point)
        d = GeometryUtil.relativeDistFromPointToLineSegment( node.position, join.otherNode.position, tap.position );
        // If this is closer, remember this one
        if (isCloserThanWhatWeHave( d )){
            // Remember this one
            rememberClosestSegment( d, join );

    // Now we have the closest segment. Find the point closest to the tap
    point = GeometryUtil.closestPointOnLineSegment( closestJoin.node.position, closestJoin.otherNode.position, tap.position );

Note that most of the work of finding that last ‘point’ using closestPointOnLineSegment is already done during the relativeDistFromPointToLineSegment function call. If you take a look at the definitions for these two functions you’ll see there is basically only one line different. At some later point I’ll update my code to make use of this optimisation.

What it looks like

So this is what the path looks like in the Flash Professional IDE when I’m building it. I placed a screenshot of Mark of the Ninja in the background as a pretend level, just because. The green lines are drawn using the line tool, and are automatically converted to nodes and paths (see Creating the path above). Just ignore the purple markers and red lines around the door for now. That’ll come later when we manipulate nodes (to open/close doors etc).

Building the path

Once the code extracts the path, it draws a representation to the screen.  Tapping anywhere will find the closest point using the technique described above and place a yellow marker on it.  If you have the flash player you’ll be able to click/tap below to try it, otherwise you’ll just see a static image.

If you have Flash Player 11.6, click below to see the code in action –


Next phase, find shortest path from the last tap on the map to the next one (the actual path finding part!)

Facebook achievements API tools

Why do Facebook make their achievements so difficult to manage?  iOS game centre has a streamlined GUI dashboard that allows achievements to be created, updated and maintained, and Google Play provide a nice GUI to do the same thing.

Facebook, on the other hand, force you to build each achievement as a separate HTML file with the appropriate meta tags, maintain a unique URL, upload the files to your own server, and then manually register these by writing a script and running that on the server.  You’ll be bogged down in code trying to determine the correct access_token to use and parsing response objects and nonsensical error messages!

Maybe in time some of this at least may be available via the Facebook app dashboard.  But for now, use these scripts 🙂

These Facebook achievement helper scripts allow you to easily register achievements, update achievements and delete achievements for your Facebook app.  You’ll still have to create an HTML file for each of your achievements and upload them to your server, but you won’t have to write a line of code to register, update or delete them.

Disclaimer: First read the readme.txt in the zip for details, including the NO WARRANTY disclaimer.

Download the Facebook achievements PHP helper scripts here.

Full details of how to use the scripts are contained in readme.txt in the zip file.  But just quickly:

  1. Create your achievement HTML files and put them on your server (see FB docs). Add an extra meta tag to specify the display order (see important notes below)
  2. Unzip these (and a copy of the PHP facebook SDK) scripts to that same folder
  3. Edit _config.php with your app ID and secret, and the path to the PHP Facebook SDK
  4. Call _register.php in your browser to register achievements with FB (skips ones already registered)
  5. Call _update.php in your browser to update achievements with FB (also registers new ones)
  6. Move achievement files to a ‘delete’ subfolder and call _delete.php to delete achievements from FB

Some important notes:

  • Add an additional meta tag to your achievements to specify the display order. This is the order that Facebook displays your achievements in a list to the user.  The number must be an integer and be unique.  lower numbers appear before higher numbers in the list.  the meta tag is: <meta property=”order” content=”42“/>
  • You can update achievements by registering them again, but Facebook states that ‘after a large number of updates, the achievement will be locked and no longer editable’. Just a warning.
  • Facebook do not recommend deleting achievements unless you are doing so during development/testing

Hope it helps!

Flash IDE – Rename/renumber multiple instances on the timeline

I needed to re-number a whole bunch of instances on the stage today, so wrote a handy JSFL script to do so.  Feel free to use this script as-is where-is (I give no guarantee that it’ll work for you, and I’m not liable for any issues that may arise from it’s use).

Having got that out of the way, here is what it does:  Say you have a lot of instances that are named sequentially on the stage (such as obj7, obj8, obj9, obj10) etc, and then you decide to delete one out of the middle, or add one in to the middle.  Usually this then means manually renaming all other instances to create a new sequence.  if you have literally hundreds of these (like I did), that can be quite painstaking.

With this script you simply select the first and last instances on the stage to rename and select ‘Rename sequential stage objects’ from the ‘Command’ menu.  The instances all need to have the same instance name prefix (for example, all named ‘obj#’ where # is the number). You’ll be prompted to enter a number to start renaming from, and the script will make short work of the rest.

Tested with Adobe Flash Professional CS6, but theoretically it should work with versions from CS3 onward.

Note: it does NOT zero pad – but that’s a relatively simple change you can make 🙂

Here’s how to install it:

  1. Download Rename sequential stage objects JSFL file (zip) and unzip it
  2. Copy/move the .jsfl file to the Command folder for Flash (see below)
  3. The command is now available in the menu

Where to put the jsfl file (see Adobe site for latest info):

  • Windows 7: boot drive\Users\username\AppData\Local\Adobe\Flash CC\language\Configuration\
  • Windows Vista: boot drive\Users\username\Local Settings\Application Data\Adobe\Flash CC\language\Configuration\
  • Mac OS X: Macintosh HD/Users/username/Library/Application Support/Adobe/Flash CC/language/Configuration/


AS3 – Cutting a shape out of a bitmapData

Not sure what to call this (or what others will search for):

  • Cutting a shape out of a bitmapData without using a mask
  • Masking a bitmap with a shape

But here is the solution 🙂

If you have a shape (for example a circle, or maybe a complex shape), you can cut out a bitmap in this same shape using the steps below.  My example uses a ‘Shape’ instance as the ‘mask’, but you can easily use a Sprite or MovieClip instead, or remove a step and use another BitmapData as the mask.

The basic principle is:

  • Convert the mask to a bitmapData (if it isn’t already) using bitmapData.draw
  • Copy only the ALPHA channel from the mask to the source bitmap

Note that if the source image also has alpha, the alpha channel will be replaced by that of the mask, so the image may not look right.  If you need to mask a source image with alpha (for example a transparent PNG) then you can’t use this method.  See below.

In my example below I do it slightly differently.  The above steps will not preserve the source (the source alpha channel is modified).  Instead I do it the following way.  It uses more processing as it needs to copy 3 channels instead of 2, but it preserves the source:

  • Convert the mask to a bitmapData (if it isn’t already) using bitmapData.draw
  • Copy the RED, GREEN and BLUE channels from the source to the mask bitmapData, leaving the ALPHA intact
  • Use the mask bitmapData as your new bitmap

Here is the code (remember to import all the classes used below):

 * Cuts the bitmap out in the shape provided. Please ensure that shape.x and shape.y are
 * relative to bitmap (for example 0,0 is top left of bitmap). This way you can position the
 * shape within the bitmap. It can also be rotated and scaled etc. Important: The original bitmap
 * is unchanged and a new bitmap is created.
 * @param bitmapData The source image
 * @param shape The shape to cut out
public function cutShapeFromBitmapData( bitmapData : BitmapData, shape : Shape ):BitmapData {
    // Copy the shape to a bitmap
    var shapeBitmapData : BitmapData = new BitmapData( bitmapData.width, bitmapData.height, true, 0x00000000 );
    shapeBitmapData.draw( shape, shape.transform.matrix, null, null, null, true );
    // Now keep the alpha channel, but copy all other channels from the source
    var p : Point = new Point(0, 0);
    shapeBitmapData.copyChannel( bitmapData, bitmapData.rect, p, BitmapDataChannel.RED, BitmapDataChannel.RED );
    shapeBitmapData.copyChannel( bitmapData, bitmapData.rect, p, BitmapDataChannel.GREEN, BitmapDataChannel.GREEN );
    shapeBitmapData.copyChannel( bitmapData, bitmapData.rect, p, BitmapDataChannel.BLUE, BitmapDataChannel.BLUE );
    // Tada!
    return shapeBitmapData;

As mentioned above, if your source image has an alpha channel that you wish to preserve (like a transparent PNG) then the steps are as follows:

  • Create a new bitmapData the same size as source (we’ll call ours ‘dest’)
  • Fill it with a solid color (e.g. 0xffffffff)
  • Draw the mask on to dest using BlendMode.ERASE. This will cut out a hole the same shape as your mask
  • Now draw dest on to source  also using BlendMode.ERASE. Done

Edit: The ‘copyPixels’ method lets you copy color data from one bitmap and alpha data from another bitmap, so another solution to this problem is:

  • Convert the mask to a bitmapData (if it isn’t already) using bitmapData.draw
  • Create a new bitmapData the same size as source (we’ll call ours ‘dest’)
  • Use copyPixels to copy the source image pixels to dest, while copying the alpha data from mask

Flash Develop – Error: Comparison method violates its general contract!

We’ve come across this error several times during the development of our last few games.  The error occurs when compiling from Flash Develop.  The error can usually be side-stepped by cleaning and then building (SHIFT+F8, F5), but this can be a hassle, and it’s always nice to try to remove these errors entirely.

According to others who have had the issue there can be many causes for this error. However, in our case, the error related to the naming of symbols within a swc file included in the project.

It seems if any two (or more) symbols on the same timeline have the same instance name, this error will occur.  For example, if you add a MovieClip to the stage and name it ‘clip1’, then copy and paste it, both of these symbols will have the same instance name of ‘clip1’.  It doesn’t matter if they are both on the same frame, or if they are on different frames of the same timeline – if you now include this as a swc to your FlashDevelop project you will likely get the contract violation error.

This works for any timeline, not just the stage – so be careful about all your nested MovieClips.  For example, if you add a MovieClip to the stage, and then within that MovieClip you have two symbols with the same name you will also get the error.

In our case the culprit was a button MovieClip with 2 frames – a ‘normal’ frame and a ‘pressed’ frame.  On both frames the background of the button was called ‘bg_clip’.

GoViral extension and FB_LOGIN_CANCELED

We’re using the milkmangames GoViral extension (3.0.3) for a current project and running into a weird error where logging in to the iPhone5 raises a gvFacebookLoginCancelled (FB_LOGIN_CANCELED) event even though we click the [OK] button on the login dialog.

If this happens to you, check your Facebook app settings (at http://developers.facebook.com/) to make sure that your app ID matches the one used in your application descriptor.

We discovered the fix when trying the same app on iPad1.  It uses the external Facebook app for authentication – and the app raised an error message with more details on it.

History repeats

Back in 2007, well before iOS and Android were around, Pixelthis released a puzzle game for the mobile phones of the day called Rune Mage.  Rune Mage was available all over the world, but performed particularly well on the Verizon network in the US, where it was part of a catalog called ‘Smashing Games’.  It did so well, in fact, that it regularly outperformed well-known branded titles like Ben10 and Angry Beavers within the catalog.

A lot has happened to the mobile landscape in the past 6 years.  Phones don’t have number pads any more, and games don’t need to remain under 300kB – but I am pleased to announce that Rune Mage is still here, and will be making a reappearance on iOS, Android and Facebook – bigger and badder than before, with HD graphics, 3 times as many levels, and other awesome game play mechanics that will be revealed in good time.

Here are some screenshots of the Rune Mage of yesteryear. Have a good snigger 🙂

Video games help slow learners


A world-first video game solution to help children with learning problems

PALMERSTON NORTH, New Zealand – March 26, 2013 – Pixelthis announced today the release of a suite of games for iPad, PC and Mac to detect and treat learning problems in children.  The games have been developed for Napier-based auditory processing support specialists, Acoustic Pioneer.

The Acoustic Pioneer tool kit, available at www.acousticpioneer.com, allows audiologists and other speech and language professionals to assess children for brain-related auditory processing disorders (APD).  The games check to see how well the child’s brain processes auditory information in a variety of situations.  These situations correlate to the classroom and other real-life scenarios.  Auditory processing skills have a profound effect on reading and wider learning skills.

With no software development background himself, Acoustic Pioneer founder Dr. Matthew Barker (AuD) worked closely with Pixelthis to commercialise his idea.  “[Dr. Barker] knew what he wanted as it related to Audiology,” says Peter Vullings, “and we translated that into the actual games and tools that he required to make it reality.”.  Dr. Barker adds “Without the experience and knowledge that Pixelthis brought to the table, I would not have been able to realise my vision.  They have taken my input and turned it in to a set of games and products that work amazingly well.  Pixelthis have made the process simple and enjoyable.”.

Pixelthis have also developed a suite of training games (or ‘auditory exercises’) for Acoustic Pioneer that children play to improve certain aspects of their auditory processes.  The games improve the core processes that effect reading and learning, and therefore the future prospects of the child.

Pixelthis more recent projects include FarmHelp (www.farmhelp.co.nz) an on-farm tutorial app for Android phones aimed at life-stylers and farmhands, RaceMyGhost (www.racemyghost.com) a training app for indoor cyclists for iPads and iPhones, and “Rescue 1: lift off” a helicopter rescue game set in New Zealand where a proportion of proceeds were donated to Auckland’s rescue helicopters.

The Acoustic Pioneer tool set is available now from www.acousticpioneer.com.

About Acoustic Pioneer

Acoustic Pioneer are cutting-edge support specialists for all professionals working in the field of Auditory processing.  They provide simple to use, cutting-edge tools to help professionals get the most information possible about each client in order to make the best possible diagnosis.  For all enquiries, contact info@acousticpioneer.com

About Pixelthis

Pixelthis develops apps and games for mobile devices and social networks.  They are one of New Zealand’s most experience game studios with over a hand in over 400 projects for more than 100 clients over the past 9 years.  To talk to Pixelthis about your project, contact Peter Vullings at peter@pixelthis.co.nz

R3bound released – experimental action-puzzle game!

Pixelthis is proud to announce the r3lease of R3bound for iOS and Android.

R3bound is an experimental action-puzzle game, based on the laws of momentum and Newton’s cradle.  Match stacks of the same colour to clear the board and move through the levels,  The dynamic audio track amps up as you improve, and a multiplier ensures monster scores.  Use exploding blocks and rainbow blocks to your advantage, while the colour-changing blocks and locked blocks will twist your brain.

R3bound is hard. We’re not going to pretend it isn’t.  But once you get the hang of it you’ll be hooked.  Are you up for the challenge?

R3bound is completely free, but if you want to see it developed further you can support Pixelthis through an in-app pledge of $0.99.  We have some fantastic ideas and many more levels planned, but we can’t realise them without your help!

Click here to get R3bound now for iOS!