Goodbye apple, hello android incredible

Flash developers unite. Ditch apple iPhone and get the Android.

The ultimate chair – Herman Miller Embody

Took the executive chair back to costco and replaced it with the Herman miller embody chair. As comfortable as the costco chair looked, it is not suitable for working.
Executive chairs are inclined slightly backwards so after few hours on the computer creates a stress on your neck. Chairs made for working has a slight incline forward making it easier to sit for many hours.

Actionscript 3: Detect hidden movieclip on stage overlapping buttons

If  you run into issues with an invisible display object covering your button but you don’t know where it is, this handy code snippet I got from my co worker Kris can trace it out for you.

Just drop it in your constructor.

stage.addEventListener(MouseEvent.CLICK,_checkMouseEventTrail,false,0,true);
function _checkMouseEventTrail($e:MouseEvent):void
{
var p:* = $e.target;
while(p)
{
trace(">>", p.name,": ",p);
p = p.parent;
}
};

Actionscript 3: Using modulos to wrap a moving movieclip

A clean way to wrap a movieclip wrapping around the stage is to use modulos

var widthOfStage:Number = stage.stageWidth;
var velocity:uint = 1;
myClip.x = (myClip.x + velocity) % widthOfStage;

That part is easy. The difficult part is handling moving left when you encounter negative number. The solution to that is to add the original width back in to keep it positive.

var velocity:uint = -1;
myClip.x = widthOfStage + ((myClip.x  + velocity) % widthOfStage);

A problem you might occur is if you try to move back right, your clip might jump. So to keep both left and right movement synced modify the original right movement to:

var velocity:uint = 1;
myClip.x = widthOfStage + ((myClip.x  + velocity) % widthOfStage);

[ad#Google Adsense]

Actionscript 3: Bold not working on external fonts in a font family.

There was an issue with compiling external font swf made up of a font family in flex builder. For example when trying to generate a set of AkzidenzGrotesk regular, light, bold and black the bold will now show up.

Here is a typical font embedding code in an actionscript project.

package {

	import flash.display.Sprite;

	public class AkzidenzGrotesqueBold extends Sprite
	{

		[Embed(source='assets/AkzidenzGrotesk-Bold.otf',  fontName='AkzidenzGrotesqueBold')]
		public static var AkzidenzGrotesqueBold:Class;

	}
}

Every font will compile and generate a corresponding swf except bold.

To get around this issue make sure to define the font weight.

package {

	import flash.display.Sprite;

	public class AkzidenzGrotesqueBold extends Sprite
	{

		[Embed(source='assets/AkzidenzGrotesk-Bold.otf',  fontWeight='bold' fontName='AkzidenzGrotesqueBold')],
		public static var AkzidenzGrotesqueBold:Class;

	}
}

Don’t bother defining the fontFamily=”AkizidenzGrotesk”, CSS in flash will ignore it. It only uses the fontName=”blah”.
Bold font should have fontWeight=”bold”, italic font should have fontStyle=”italic” and a bold italic should define both.

Hope that helps
~mark

[ad#Google Adsense]

Actionscript 3: Get ratio value between two numbers

Simple utility for getting a ratio between two numbers. Thanks to my friend Jamie for the method.


private function returnValue(value:Number, actualMin:Number, actualMax:Number, ratioMin:Number, ratioMax:Number):Number{
     return (((value - actualMin) / (actualMax - actualMin)) * (ratioMax - ratioMin)) + ratioMin;
}

Here is also a simpler version when you know the percentage of the number range.


public function returnValue( percentage:Number, min:Number, max:Number ):Number {
    return ((( max - min ) / 100 ) * percentage ) + min;
}

This version returns a percentage of the two range of numbers.


public  function returnValuePercentage( _value:Number, min:Number, max:Number ):Number {
return ((( _value - min ) / ( max - min )) * 100 );
 }

[ad#Google Adsense]

Actionscript 3: Detect the difference between a Mouse click and a Mouse drag.

How do you tell if the user clicked or dragged in your flash app? Take a look:

private var time:uint;

function onMouseDown(event:Event):void {
     time = getTimer();
     startDrag();
}

function onMouseUp(event:Event):void {
     var diff = getTimer() - time;
     if (diff < 250) {
           trace("clicked");
     }
     stopDrag();
}

[ad#Google Adsense]

Actionscript 3: Move first array index to the back and back to front

Here is a very cool line of code to manipulate an array.

If you want to take the first item of an array and place it at the end:

myArray.push(myArray.shift());

If you want to take the last item of an array and place it back at the front:

myArray.unshift(myArray.pop());

[ad#Google Adsense]