In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

AlphaBitmapFill

This comes at a price, you DO have to copy your BitmapData - only flash does it itself for you behind the scenes.
Get Adobe Flash player
by makc3d 23 Sep 2010
    Embed
/**
 * Copyright makc3d ( http://wonderfl.net/user/makc3d )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/rqmf
 */

package {
	import com.actionscriptbible.Example;
	import flash.display.BitmapData;
	import flash.display.Shader;
	import flash.display.Sprite;
	import flash.geom.Matrix;
	import flash.system.System;
	public class AlphaBitmapFill extends Example {//Sprite {
		public function AlphaBitmapFill () {
			graphics.beginFill (0x7F);
			graphics.drawRect (50, 70, 450, 100); graphics.endFill ();

			var a:uint = System.totalMemory;

			var bmp:BitmapData = new BitmapData (100, 100);
			bmp.noise (123);
			var mat:Matrix = new Matrix; mat.ty = 20;
			graphics.beginBitmapFill (bmp, mat);
			graphics.drawRect (0, 20, 100, 100); graphics.endFill ();

			var b:uint = System.totalMemory;

			//[Embed(source = 'Alpha.pbj', mimeType = 'application/octet-stream')]
			//var PBJData:Class; var s:Shader = new Shader (new PBJData);
			var s:Shader = new Alpha;
			s.data.src.input = bmp; mat.ty = 130;
			for (var i:int = 0; i < 5; i++) {
				s.data.alpha.value = [1.0 - i * 0.15];
				mat.tx = 110 * i;
				graphics.beginShaderFill (s, mat);
				graphics.drawRect (mat.tx, mat.ty, 100, 100); graphics.endFill ();
			}

			var c:uint = System.totalMemory;
			trace ((c - b) / (b - a));
		}
	}
}

/**
 * Thanks http://wonderfl.net/c/skpS
 * Shader code:

<languageVersion : 1.0;>

kernel Alpha
<   namespace : "experimental";
    vendor : "makc";
    version : 1;
    description : "alpha";
>
{
    parameter float alpha;

    input image4 src;
    output pixel4 dst;

    void
    evaluatePixel()
    {
        pixel4 p = sampleNearest (src, outCoord ());
        p.a = alpha; dst = p;
    }
}

 *
 */
import flash.display.Shader;
import mx.utils.Base64Decoder;
class Alpha extends Shader
{
	public function Alpha()
	{
		var dec:Base64Decoder = new Base64Decoder();
		dec.decode( "pQEAAACkBQBBbHBoYaAMbmFtZXNwYWNlAGV4cGVyaW1lbnRhbACgDHZlbmRvcgBtYWtjAKAIdmVyc2lvbgABAKAMZGVzY3JpcHRpb24AYWxwaGEAoQECAAAMX091dENvb3JkAKEBAQAAAmFscGhhAKMABHNyYwChAgQBAA9kc3QAMAIA8QAAEAAdAwDzAgAbAB0DABAAAIAAHQEA8wMAGwA=" );
		this.byteCode = dec.toByteArray();
		dec = null;
	}
}