Get alpha value for a bitmap’s pixel

October 5th, 2009

This goes through every pixel of a bitmap image…

var bmd:BitmapData = _bitmapdata;
var pixelValue:uint;
var alphaValue:uint;
var w:int = bmd.width;
var h:int = bmd.height;

for(var i:int =0; i< w;i++){
    for(var j:int =0; j< h;j++){
        pixelValue = bmd.getPixel32(i,j);
        alphaValue = pixelValue >> 24 & 0xFF;
    }
}

Flash 10 Text Transform Hack from BIT-101

September 24th, 2009

BIT-101 blog has a great hack for using Flash 10 to scale or rotate text super smoothly without having to embed anything. Instead of using 2D properties, use Flash 10’s 3D properties.

Hack of the Day: using 3D on text in lieu of embedding fonts.

AS3 URLLoader class for data requests and responses

September 22nd, 2009

Today I needed to send some variable data to a script on another server and display a success or failure message based on the response from that script. Of course I did not want to use getURL() because that would open up the URL in the browser. The URLLoader class allows me to make my request and receive a response without loading the response in the browser.

1) Create variable data to send with the request:

var vars:URLVariables = new URLVariables();
vars.someVariable = someVariableValue;
vars.anotherVariable = anotherVariableValue;

2) Create the request:

var req:URLRequest = new URLRequest(someURLString);

3) Set the data and method:

req.data = vars;
req.method = URLRequestMethod.GET;

4) Create the loader and set any event handlers you need:

loader = new URLLoader();
loader.addEventListener(Event.COMPLETE, completeHandler);
loader.addEventListener(ProgressEvent.PROGRESS, progressHandler);
loader.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);

private function completeHandler(e:Event):void {
     var responseString:String = loader.data;

}

private function progressHandler(event:ProgressEvent):void {
     trace("Loading: " + Math.floor((event.bytesLoaded / event.bytesTotal) * 100) + "%");
}

private function errorHandler(e:IOErrorEvent):void {
     var error = "Error occured.";
     trace(error);
}

private function securityErrorHandler(event:SecurityErrorEvent):void {
     var error = "Security error.";
     trace(error);
}

5) Then load the request:

loader.load(req);

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/URLLoader.html

Strict mode and fullScreenSourceRect

July 9th, 2009

I puzzled for a while today over why my flash file wouldn’t publish without errors. It kept giving me the compile time error about not recognizing “fullScreenSourceRect” – even though I have used it many times in other projects, in the same development environment and with the same version of Flash. Finally I realized the file was publishing in strict mode. Turning that off did the trick.

Google now indexes dynamic flash content including xml

June 21st, 2009

Google has announced they have added external resource loading to their flash indexing capabilities. This means they can now crawl and index dynamically loaded content, which includes content loaded through external xml files. This is exciting news for developers who build large flash sites and load content through xml or other external files including text, html or swf files. Previously this content was inaccessible to Google’s search engine spiders which meant valuable data in flash websites wasn’t being indexed and used in generating web search results.

Google’s Official Webmaster Central Blog announcement

PC World: Google Improves Flash Search and Indexing

Design Patterns: Strategy

June 15th, 2009

The Strategy design pattern incorporates the object oriented concepts of encapsulation, composition and polymorphism.

The most straightforward explanation of the technique is to encapsulate the part of your code that will change, and to favor composition over inheritance.

This means separating algorithms into their own object classes and making them interchangeable (polymorphism) so their use can be swapped out at run-time.

The composition over inheritance idea means to think of objects in terms of “has-a” relationships instead of “is-a” relationships. By avoiding the use of inheritance where we want to extend object behaviors and instead using composition as our method of extension, we avoid creating many generations of code that require more work when updates are needed and introduce fewer bugs because we are adding new code, not modifying old code.

Tools to help in dealing with image sequences on the timeline

June 11th, 2009

Download these time saving tools when you need to sequentially extend or clear a large number of frames.

http://www.toonmonkey.com/tween2keys.mxp: will clear every other frame
http://www.toonmonkey.com/frameExtender.mxp: will extend each frame

Alpha transparency on objects with children

June 11th, 2009

Ever tried to change the alpha of a movieclip or sprite with multiple children and been annoyed that you can see all of the children changing their alphas separately, creating an undesired effect? An awesome trick is to apply an empty filter, like a blur of 0, and the parent object will be treated as one solid object and give the desired alpha transparency effect. See it in action here:

http://labs.eric-decker.com/?p=178

Update:

My manager, Mark, noticed in the comments of the page I blogged on previously that there’s an even better way to accomplish this…

“If you set the blendMode of your containing DisplayObject to BlendMode.LAYER Flash will consider this DisplayObject as only one layer and will change the alpha the way you normally think it would.”

http://www.zedia.net/2008/blendmodelayer-a-must-when-changing-alpha-of-a-displayobject-containing-other-displayobject/