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?