26 November 2008

YouTube Mashing

I was listening to BBC 6 Music, a cracking radio station that plays amazing new stuff you've never heard of, when I was sent the standard YouTube comedy clip of kittens doing silly things.

I was listening to Smoke Fairies - Living with Ghosts when I opened the kitten video.

By pure luck, I opened the video at the perfect moment in an almost seemless mix with the radio.

Try it yourself, follow these instructions:

  1. Load each video in a separate browser tab or window.

    Here's the Smoke Fairies video:
    http://www.youtube.com/watch?v=4ey8UQ21_jk

    And here's the "Lookin' Kitties" video:
    http://www.youtube.com/watch?v=MnR3bAICsDM

  2. Press pause on both videos until they're completely downloaded.

  3. Cue the Smoke Fairies video to about 1:48

  4. In a quick manoeuvre, start the Smoke Fairies video, then flip to the kitties video and press play.


Goes together pretty well doesn't it?

So budding DJ's, get out there and start a new trend,
"YouTube Mashing" ! But don't forget, you heard it here first ;-)

24 November 2008

Glenbow Museum - Art Pad

Here lies ArtPad:

http://www.glenbow.org/artpad

Technically it's a fantastic site. I only worked on a very small part of it myself, but many of my colleagues worked very hard to produce a site which is artistically stunning, yet adheres to strict accessibility standards - a tough job!

A big hurrah to everyone who worked on it. A slow clap to the fact it was poorly managed, vastly over budget and released 2 years after it was initially completed.

04 November 2008

Accessing Scenes in loaded SWFs (AS3)

Ok, ok, I can hear you now, "don't use scenes, silly boy!", but really, they're the best compromise to allow animators to freely draw avatars and allow me to control the avatar orientation with each scene.

Animators would send me swfs containing scenes named as each avatar orientation (N, S, E, W etc). I would then load these swfs into the game and use the scenes to control the avatars orientation. The problem is I couldn't access any of the scenes I got from the animators swfs. My proof of concept worked perfectly, but when I got the real stuff, it wasn't working!?

If I checked loadedMC.scenes.length, I would get a value of 1 instead of the expected 5, yet it would still cycle through all the scenes, but where were they?

I asked for the fla's and all seemed fine. However there was 1 minor difference: the animators were using Graphic symbols on the timeline in each scene, not MovieClips. I added a blank MovieClip to each scene and hey-presto, the scenes were accessible!

So if you use scenes, make sure you have MovieClip symbols inside them, otherwise you won't be able to access them at run-time.

*** Update ***
Please read comments to this post

16 October 2008

My Intel iMac is dead, logic board failure, how's yours?

With much dismay, I resigned myself to the fact my 2006 17" Intel iMac is kaput. I've had it since July 2006, so in just 2 years and 3 months it's died. It's the first total failure of any PC I've ever owned and also turns out to be the most expensive. To replace a logic board here in Canada costs around $1000, so it's an economic write off, I might as well buy a new machine.

When I bought the machine in the UK, back in 2006 I didn't bother getting AppleCare as I thought it was just another extended warranty you don't need. Somewhat ironically I think there's a European consumer law (which I'll have to research), that covers you outside the 1 year manufacturers warranty, but now I'm in Canada, I doubt that applies.

Two things disappoint me here:

1) It's shattered my perception of Apple producing reliable machines. I've been using Macs for years with no trouble with the machines at all. The expensive price tag stood for style and reliability - something that was made to last.

2) The sheer expense to myself. What ever I do, it's going to cost me. I cannot afford another Mac for a few months now and I'm back to using my old Sony Vaio, which the Mac replaced and is still going (it just about runs Flex 3). I need a machine to do my work, but can I really justify buying another iMac at $1500+ ? In Canada, Apple doesn't offer any credit schemes and I'm only allowed a $500 credit card limit as I've not lived in the country for long. It pains me to be actually considering buying a PC with Vista on it!

Doing a bit of Goolging and speaking to the guy in the Apple Store, it seems early Intel iMacs are prone to this problem. Potentially thousands of machines could be dropping like flies, out of warranty and at great expense to the consumer. Apple are probably keeping this one quiet, so please post here if you've had a logic board failure (or any other catastrophic problem) with the 2006/2007 Intel iMac models (the white ones).

**** UPDATE - MARCH 2011 ****
Thank you everyone for posting. There is a petition you can sign to recall 2006 iMacs.
http://www.petitionspot.com/petitions/imacrecall

Alas I ripped my iMac apart to get the HDD out and sent it for recycling. But if you still have your dead iMac, it may be worth signing the petition and get on a Class Action Lawsuit.

01 October 2008

Flash Player Audio Sync and Frame Rates

So, it's the end of my hiatus since I last posted. I got married, changed job, house, car - actually pretty much all my life.

I'm back to creating Flash games, which is always enjoyable. I'm currently building a multiplayer world and various games attached to it. At the moment I'm building a Dance Dance Revolution type game which initially sounds simple, and it would be, but for the fact the Flash Player frame rate is all over the place.

If you have a 24fps movie, each frame should fire every 41.166* ms - or they *should*. In reality the frame rate can vary +- 20ms, which means after a short while the animation drifts away from the audio quite considerably. This problem is caused by a number of factors, mainly CPU speed/load and platform. It's bad on PC but terrible on an Mac.

So the problem is how do you get your beat hits to be absolutely precise to the music? I've managed to solve this problem by creating a "deltaTime" variable which calculates the drift per frame. If you know how many milliseconds it should be and how much drift you have, you can convert that to pixels to move, based on frame rate.

The net effect is a bit weird. The beat hits are spot on with the music, but this comes at a price because as the instructions scroll down the screen, the distance the instruction icons move is different each frame. This results in a jerky scrolling motion.

I'm hoping FP10 has more accurate frame rates that would solve this problem.

25 March 2008

The Statistics of Argh!

You know those days when you just cannae take it any more (Capt'n) and end up typing "AAAAARRRRRRRRRRRRRRGGGGGHHHHH!!!!" into Google? Yet have you ever wondered how many AAAA's RRRR's GGGG's and HHHH's to use?

Well here's the answer:
http://osteele.com/words/aargh

The most common spelling appears to be "argh", which is really more of an apathetic sigh than a gut wrenching scream of annoyance.

Only 14 people seem to have gone with my spelling of 5 A's and 15 R's. You certainly need more than one A to get it going and there definitely needs to be more R's in the "argh" as I consider that the "body" of the scream when it audibly starts to blend with the multitude of A's.

What the statistics don't show are the G's and H's which, in my opinion, round the scream off. You need a good few G's to release that guttural sound of pain, followed by a few strained, aspirated H's as your lungs, exhausted of air, begin to collapse.

You see? T'interweb has its uses!

Back to work.... AAAAARRRRRRRRRRRRRRGGGGGHHHHH!!!!

18 March 2008

Use Weak References for Your Event Listeners

Please read this:

http://www.gskinner.com/blog/archives/2006/07/ as3_weakly_refe.html

Using weakly referenced event listeners means an object can be cleared during Garbage Collection even if there's an event listener acting upon it.

It's very useful when you're spawning / deleting a lot of objects, in my case bubble "bullets" that I'm firing at targets underwater.

It saved my bacon (and my forehead) as I've been banging my head on my desk wondering why objects I thought I'd removed still persisted in memory.

The fact it's not a default setting and not very well explained, nor is its importance highlighted (this should be stapled to the front of the Flash CS3/Flex DVD box), is bloody annoying.

Thanks Grant.

24 February 2008

Creating Class Instances from a DisplayObject in AS3

*** The technique below doesn't clone a class instance, but allows you to create a new class instance derived from an unknown DisplayObject ***

After selecting an item by clicking the mouse, I needed to create a new instance of the selected item to be added to an item inventory. I needed to find out what type of object was being passed into the MouseEvent handler so I could create a new object of a specific type i.e.

private function mouseHandler(e:MouseEvent):void
{
// this is only a DisplayObject - what is it?
trace(e.target);

// this is what I want to do, but how do I know if e.target is a Rock?
var newItem:IItem = new Rock();
}

The following function uses flash.utils.getQualifiedClassName() to return a string that contains the name of the class including full namespace.

It then uses flash.utils.getDefinitionByName() to return a Class object which can then be used to create a new class.

public function duplicateItem(obj:*):*
{
var className:String = getQualifiedClassName(obj).split('::').join('.');
var ClassRef:Class = getDefinitionByName(className) as Class;
var item:* = new ClassRef();
return item;
}

So to create a duplicate object, just use call the duplicateItem function. You can also cast the returned class instance, if required, as shown below:

private function mouseHandler(e:MouseEvent):void
{
var newItem:IItem = duplicateItem(e.target) as IItem;
}

29 January 2008

Flex 2: Embedding Flash 9 swfs and controling the MainTimeline

I've been embedding Flash 9 swfs into a Flex 2 project using the following code:

[Bindable]
[Embed(source="myFlash9.swf")]
private var mySwf:Class;

This creates the bindable variable "mySwf" which can be bound to the backgroundImage attribute of certain components e.g.

<mx:Canvas backgroundImage="{mySwf}" />

However much I tried, I couldn't access the timeline of that swf as it was cast as a Class type and essentially wasn't a MovieClip. Flex only permits Class or String variables when embedding in this way.

I needed to find a way to load a swf into Flex and use it as a fully accessible MovieClip. Here's what I did:
  • Create a bindable MovieClip variable
  • Load in the swf using the flash.display.Loader class
  • Assign the result from the Loader class to the bindable MovieClip variable
  • used the Image component in Flex to add the swf to the application

Here's the complete MXML code:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
<![CDATA[
import flash.net.URLRequest;
import flash.display.MovieClip;
import flash.display.Loader;
import flash.events.*;

[Bindable]
private var mySwf:MovieClip;

private function init():void{
var bgURL:URLRequest = new URLRequest("Test.swf");
var bgLoader:Loader = new Loader();
bgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
bgLoader.load(bgURL);
}

private function completeHandler(event:Event):void {
mySwf = event.target.content as MovieClip;
mySwf.gotoAndPlay(20); // access the timeline of the loaded swf
}

]]>
</mx:Script>

<mx:Canvas width="856" height="527" horizontalCenter="0" verticalCenter="0">
<mx:Image source="{mySwf}" />
</mx:Canvas>
</mx:Application>


You can now directly access the timeline of the loaded swf using the "mySwf" variable.

Using the backgroundImage attribute caused errors as it expected a Class variable to be passed into it. Using Image seems to have got around this problem.

15 January 2008

Calgary Flash and Flex User Group Meetings

It'll be an interesting couple of months with the releases of Flex 3 and AIR and as usual, Adobe reps are doing their pre-release tours.

There are 2 events in Calgary that can't be missed:

14 January 2008

AS3 mp3 streaming problem with Facebook

I created a Flash game for Facebook and had a problem with the audio I was streaming through the Sound class. Loud clicks, pops and squelches ruined the audio, hurt my ears and probably didn't do my speakers any good!

This problem only occurred when the swf was embedded in Facebook, tests on other servers did not produce this error.

To fix this problem I did the following:

  • Set Securtiy.allowDomain("foo.com"); in the document class

  • I also specifically set the policy file with Security.loadPolicyFile("http://www.foo.com/crossdomain.xml");

  • In crossdomain.xml, add the to-ports attribute:
    <allow-access-from domain="www.foo.com/" secure="false" to-ports="*" />


This removed all clicks, bleeps and squelchy noised from the audio. I guess it has something to do with Flash only granting access to ports 1024 and above by default. Specifying to-ports="*" presumably allowed access to all available ports below 1024 and the mp3 streamed without any problems.

This documentation helped: Security.loadPolicyFile()

Canadian Cell Phone Industry - a rant!

I've about had it with the cell phone industry in Canada. Coming from the UK, it seems about 5 years behind, the networks and available phones are pants and it's run by a few restrictive monopolies - I guess an oligopoly(!) - that expect you to sign up for 3 year contracts so you can get a Sony Ericsson K790 for only $129 dollars - it's bloody free in the UK on a 1 year contract! And 3 year contracts? I don't know where I'll be in 3 months!?

So here's the rant I sent to the Canadian Radio Television and Telecommunications Commission.

Complaint Against Bell, Rogers and Other Network Owning Cellular Phone Companies in Canada


Introduction
The general consensus among most writers in the technology industry is that mobile communications will become ever more transparent and ubiquitous

Most nations in Asia, Europe, the America’s and indeed Africa have comprehensive cell phone networks. The services offered by these networks vary from country to country but of all the 1st world counties, Canadian companies appear to be providing some of the worst service to its consumers.

Although tariffs in Canada are also not consistent with other parts of the world (e.g. paying for incoming calls) this complaint concentrates on a more holistic view of the entire cell phone industry in Canada.

How Canadian Cell Phone Companies Fail the Consumer
Buying a cell phone from any company in any country isn’t simple. There are always hidden charges and contractual obligations that the consumer has to decipher and there are always new plans with different more elaborate pricing structures being created on a regular basis. This is an industry wide problem and not specific to Canadian companies.

There are 3 mains reasons why the Canadian companies offer worse service to their consumers than other 1st world (and some developing) countries, with each reason a consequence of the reason before it:

  1. Canadian cell phone networks are not up to the standards of other 1st world nations e.g. 3G HSDPA networks in most of Europe, and East Asia.

    Canada is a vast country, but most dense urban area’s still do not have blanket 3G HSDPA coverage, even as we enter the 2nd decade of the 21st century. It appears a chronic lack of investment has made Canada’s cellular services lag behind.

  2. Subsequently the range of mobile devices is poor and these devices are not as advanced as those available in other 1st world countries.

    Why would a manufacturer sell quad-band 3G phones in a country that doesn’t have the network capability to support them?

  3. Phone subsidies are small and often require 3 year contracts. The consumer still has to pay up-front for the mobile device.

    3 year contracts are not common elsewhere, but in Canada they’re used as a method to sell smart phones at a cheaper price while also locking the consumer to a company for a long period of time. In other countries, such as the UK, phone companies offer smart phones for free on 1 year or 18 month contracts that have slightly higher monthly payments (the subsidy). Usually you can stay with your provider and upgrade to the latest smart phone for free (or a small charge) at the end of your contract i.e. once per year. The consumer always has the latest device and the company has retained their business with that consumer.



Phone subsidies also play an important role in empowering the consumer with a device that can generate more revenue for the phone company (see The Monopolies are Stifling an Entire Industry)

The bottom line is that Canadians are paying more for less i.e. they’re locked into unrealistically long contracts for phones that are worse than those offered in other parts of the world.

The Monopolies are Stifling an Entire Industry
Canadians are not empowered with subsidised mobile devices, which is probably why the penetration rate of cell phones in Canada is so low (about 51%). It’s also conceivable that the number of people with top quality smart phones is also low as the consumer has to pay for it up front and/or be locked into an uncomfortably long 3 year contract.

Therefore there is only a small audience for any company offering interactive mobile services to Canadians. Services such as: SMS short code payment, Java/Flashlite games or mp3 players, mobile payment handlers, GIS / cell location services, business directories, VoIP etc.

Many of these services use data calls that network providers will charge per megabyte. The formula is simple:

Network investment + subsidised phones = more people with smart phones = more online/data services = more downloading = more revenue = more business for the networks and a 3rd party economy utilising those networks.

Conclusion
It seems ridiculous why the like of Bell, Rogers (and others) have not yet seen or acted upon this. We go back to reason #1 above: minimal investment by the network owners has provided a service which is only just good enough. They control the networks and supply of mobile devices. They must be making lots of profit by providing a mediocre service with minimal investment. They know it will cost them billions of dollars to set up modern networks to catch up with the rest of the world.

Their myopic vision is stifling not just a business sector, but an entire technological and social revolution which is happening all over the world at an incredible speed. Speak to anyone in Europe and Asia about the mobile services they use and how it fits into their life and ask a Canadian the same thing, is like asking a teenager about filing taxes: they know what it is, but they just don’t quite get it. Why? Because they’ve never been fully exposed to it.

The available interactive cellular services in Canada are at about the same level the UK was in 2002/2003 – an age in this industry. Soon, Canadians will look, embarrassed in front of the rest of the world (if they don’t already) and wonder “why are we so behind the times? Why do we not have the phones and services you can get in Europe, Asia and elsewhere?” Look no further than the restrictive monopolies of Bell, Rogers et al and the current communications regulations.


/////

There... I feel so much better. Anyone fancy joining a Campaign for Free Phones in Canada?