Filed under Tips, Tricks, and Hacks

Why there are no million dollar ideas

by

It is well known among my friends that I “do something to computers that somehow makes apps exist.” As such, I am often approached with the inevitable proposition that goes something like this: “I’ve got a million dollar idea for an app and when you build it we’ll be rich.” These pitches typically make use of the pronoun “we,” as in “we can charge 50¢ per penguin,” and a pre-meditated revenue split, as in “you can keep 50% of the penguin monies.” This is the modern version of the old favorite, “can you make me a website,” for free implied.

Some of these ideas are great, many are not. But regardless of their quality, I want to try to reset the expectations of the idea generators. I hope this post sheds some light on the legal, social and practical implications of these ideas and provides some ground rules that will help bring these ideas into fruition.

(Read the full article after the jump)

Continue reading

Tagged , ,

Enabling the Flash Debug Player on Chrome

by

After having this happen to me for the third time, I felt that it was time for me to repost this information.

The problem:

You’re positive that you just upgraded to the Debug version of the Flash Player, when you go to test it in Chrome it says that you don’t have the debug version even though it works fine in Firefox, Safari, Opera, and who cares if it’s working in IE because you would never use IE right?

The solution:

You can reinstall the player until you’re blue in the face but it won’t help. Why? Chrome manages it’s own version copy of the player so it can provide automatic updates. You’ll want to disable this version and use your default one.

Open up your Preferences in Chrome. Go to Preferences > Under the Hood > Privacy > Content Settings… > Plug-ins > Disable Individual Plugins (Or just paste chrome://plugins/ into the address bar).

You should see a plug in called Flash. If you click the Details+ button in the top right, you’ll see more info about the plug-in files themselves. You’ll probably see two versions here; one will point to the plug-in installed by Chrome

e.g. /Applications/Google Chrome.app/Contents/Versions/15.0.874.92/Google Chrome Framework.framework/Internet Plug-Ins/Flash Player Plugin for Chrome.plugin

The other points to the system folder

e.g. /Library/Internet Plug-Ins/Flash Player.plugin if you’re on a Mac

Disable the one in the Google Chrome folder and you should be good to go!

This information was originally provided to me via Arron West’s blog which has more pictures than this post if you still need help.

Tagged , ,

Snippet Saturday: quick random choice

by

Today’s Snippet Saturday (actually, Sunday) is a quick shortcut for choosing one of several strings, objects, etc. randomly.

Now, I wouldn’t really recommend using this code in a project. There are ways to do the same thing that are much more readable and less error prone. Instead, I thought it was an interesting experiment to show off some of how AS3′s syntax works for those of you who may not have seen something like this.

What’s happening here? Let’s break it down.

  • ["Alpha", "Bravo", "Charlie"] – Here we are instantiating a new array and populating it with three strings. This is essentially the same as:
    var a:Array = new Array();
    a[0] = "Alpha";
    a[1] = "Bravo";
    a[2] = "Charlie";
    
  • [...] – next is another pair of square brackets. This is an array access operator. In other words, everything between the two brackets will be evaluated as the index of the array to retrieve.
  • int(...) – This is an explicit type-cast to an int. That means that everything inside those parentheses is evaluated and flash attempts to convert from whatever data type it is to an integer. In the case of decimal numbers, they are rounded down so this is similar to using Math.floor().
  • Math.random() * 3 – random() of course produces a random floating point (decimal) number between 0.0 and (almost but not quite) 1.0. Multiplying that number by 3 (the length of the array) produces a number between 0.0 and 3.0 (technically, between 0 and 2.99999999etc).

The result, an array is created with three strings, a random number between 0.0 and (almost) 3.0 is generated, it is rounded down to an int between 0 and 2, that number is used as the index of the array to look up. The result will be randomly one of the three strings.

I hope you found this interesting!

Tagged ,

Matryoshka Functions

by


The other day, I was working with the Flex function BindingUtil.bindProperty(). I always have a hard time remembering which pair of arguments comes first, the ‘site’ or the ‘host’ and to be honest, the names don’t really make much sense to me. “Oh, if only this were an Objective-C project I would have to laboriously type out each name of each parameter.” I thought, “It would be so much more obvious if it were writen like Bind.property("foo").fromObject(bar).toTheValueOfProperty("foo").ofObject(baz);.”

What followed was the discovery/invention of just such a thing, a nested, super-verbose function. The function achieves this by returning an instance of an internal class with nothing in it except for the next step in the chain.

package
{
	public class Bind
	{
		public static function updateProperty(object:Object, property:String):BindSource {
			return new BindSource(object, property);
		}
	}
}
import mx.binding.utils.BindingUtils;
class BindSource {

	private var targetObject:Object;
	private var targetProperty:String;

	public function BindSource(targetObject:Object, targetProperty:String):void {
		this.targetObject = targetObject;
		this.targetProperty = targetProperty;
	} 

	public function whenSourcePropertyChanges(object:Object, property:String):void {
		BindingUtils.bindProperty(targetObject, targetProperty, object, property);
	}
}

To call this function you would use:

Bind.updateProperty(foo, "bar").whenSourcePropertyChanges(baz, "bar");

Kinda cool! I soon realized that this technique has some characteristics that Objective-C messages don’t have. For example, each step can use more than one parameter (plus they each get their own code hinting). You can also provide multiple choices for what to do next providing a sort of branching behavior.

AngleFinder.getAngleOfVector(4, 4).inDegrees() 	// 45°
AngleFinder.getAngleOfVector(4, 4).inRadians() 	// π/4

You can even do free-form stacking of functions like this.

new Calculator	(5)                    // 5
                        .plus(3)            // 8
                        .times(2)          // 16
                        .dividedBy(4)   // 4
                        .minus(1)         // 3
                        .plus(2)            // 5
                        .equals();

I proudly named these “Matryoshka Functions” after the Russian stacking dolls even though I’m sure I’m not the first to try something like this. As it turns out, they’re about 10% practical and 90% clever hack. Even though there could be some potential use for this (especially with complicated, repetitive tasks), this technique conflicts too much with the way we normally code in ActionScript. Still, I thought it was cool enough to share with everyone.

Pros:

  • Very descriptive
  • Branching and stacking effect is interesting and potentially useful
  • Code hinting shows the next step in the function as well as the parameter names
  • Looks cool!

Cons:

  • Abominable code style. Too weird to be useful.
  • Difficult to know when to stop calling functions
  • Not completing the function will produce unexpected results with no compile-time errors
  • Each step requires you to pass the parameters from the previous step

Can you find any use of these? Can you think of a more efficient way to write the functions? Any other thoughts?

Check out the source with multiple examples (FlashBuilder project).
MatroshkaFunctionDemo

Killing 3D Transforms

by

Here’s a quick tip. If you’ve ever dealt with 3D in Flash Player 10+ you’ll know that DisplayObjects in 3D in Flash Player are bitmap-cached; only the bitmap representation is transformed in 3D. Recently I was working on a site where objects landed on the stage, but after landing, they appeared really muddy, which was obvious when you looked at the text they contained. Even though they were completely flat, they were still using bitmap proxies! Not great.

Turning a DisplayObject into a 3D DisplayObject is as simple as assigning a value to its rotationX, rotationY, rotationZ, or z properties. But how do you turn it back? I tried giving all these properties a value of 0, but after their animations completed they were already 0. An object at z=0 still renders in 3D, using bitmap caching. Setting these values to NaN was no better.

The solution I found is to null out the 3D transformation matrix and assign a 2D transformation matrix. This can be accomplished like so for a DisplayObject named sprite:

var matrix:Matrix = new Matrix();
matrix.translate(sprite.x, sprite.y);
matrix.rotate(sprite.rotationZ);
sprite.transform.matrix3D = null;
sprite.transform.matrix = matrix;

In this code I simply drop the transformations that are inapplicable to 2D space. This is fine when your object is already coplanar with the stage.

Anyway, quick tip if this ever had you scratching your head too.