« April 2007 | Main | June 2007 »

May 19, 2007

Credit Card Debt Take II

Some issues seem to only get worse. Some updated statistics about credit cards and debt in American since the last time I posted about this:


  • Americans spent one in seven of their take-home dollars on debt payments last year, up from one in nine in 1980.

  • In 2006, the industry mailed out nearly 8 billion credit card offers, up from 3.5 billion in 2000.

  • Credit card debt, less than $8 billion in 1968 (in current dollars), now exceeds $880 billion, more than tripling since 1988, adjusting for inflation, according to the Federal Reserve Bank.

  • In part because of the debt burden, the consumer savings rate fell below zero percent in 2005 and has stayed there.

Tags: debt

May 11, 2007

mx_internal

Sometimes you want to change the behavior of a Flex component but its hidden behind a private method or variable so you can't subclass it. Thankfully they provide the source so you can just create your own version. This is heavy handed and in some cases you just need to tweak things a little. Many components within the Flex framework have methods and properties flagged as mx_internal. These you can access without having to do anything too funky.

As an example lets change the restrict set on the input field of a NumericStepper.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
<![CDATA[
import mx.core.mx_internal;
use namespace mx_internal;
private function setupStepper():void
{
    stepper.mx_internal::inputField.restrict = "0-9";
}
]]>
</mx:Script>
<mx:NumericStepper id="stepper" creationComplete="setupStepper();"/>
</mx:Application>

The key things to note are:

  1. import mx.core.mx_internal;
    Import the namespace that is going to be used

  2. use namespace mx_internal;
    Tell Actionscript that is a namespace

  3. mx_internal::inputField
    Prefix the property name with its namespace

That's all there is to it. Happy hacking.

Tags: flex mx_internal namespace

May 3, 2007

Stopping Flash 4 SWF with Sound in Flex 2

I recently had an issue where in Flex 2 I had to load and play a Flash 4 SWF that had embedded sound in it. I'm not a Flash developer so I'm not 100% sure if the sound was encoded as an event or what have you. In any case as soon as the SWF was loaded it would start playing and it would loop. Since Flex 2 uses Flash 9 the Flash 4 SWF shows up as an AVM1Movie when loaded which means you can't do much of anything to the movie once it's loaded. Most annoyingly the sound keeps playing and playing.

Problem 1: How to stop the sound?
The only fix I found was to call SoundMixer.stopAll();. Drastic, but it worked.

Problem 2: How to stop the sound looping?
Great the sound stopped, temporarily, only problem was when the SWF looped the sound started up again. The fix requires using a Loader and a call to unload() when you are done using it:

// create a loader and load the file
var loader:Loader = new Loader();
loader.load(new URLRequest("sound.swf"));

// later when you want to stop it
SoundMixer.stopAll();
loader.unload();

Problem 3: Security issues?
This works if you are requesting the SWF from your own server, but if you are using another site to store the sound files (say a CDN), you'll run into security sandbox issues. To get around this the remote site will need to have an appropriate crossdomain.xml file and you'll need to use a custom loader context:

// create the loader context
var loaderContext:LoaderContext = new LoaderContext();
loaderContext.securityDomain = SecurityDomain.currentDomain;
loaderContext.applicationDomain = ApplicationDomain.currentDomain;
loaderContext.checkPolicyFile = true;

// use it when loading the file
loader.load(new URLRequest("sound.swf"), loaderContext);

Other notes:
You should also setup a listener on loader.contentLoaderInfo to register when the SWF has loaded as unload() only works when the loader has completed, prior to that you need to use close().

Tags: flash flex sound