Archive for snippet

Logging Php to Firebug

Ever wanted to log php to firebug? There are a lot of reasons to do this. E.g. working  on apps for a thrd party plattform like myspace.

The logger is a singleton. you can push any date type in it. the coolest part: it encodes the php class as json object.

logging_firebug

i wrapped it in a simple dummy project with some “oop” javascript in it. give it a try and tell me what you think.

and yes, i know firephp ;)

PhpLogging

Optimized edge detection algorithm.

I optimized the edge detection (sobel) algorithm found here a little. Still there is a lot potential for optimizing things. You can find tipps in joa’s wiki

Here is my code

private function detectEdges(bmd : BitmapData) : void
{
 
 var myGausianFilter : ConvolutionFilter =
 new ConvolutionFilter(5, 5, 
 [2,4,5,4,2,4,9,12,9,4,5,12,15,12,5,4,9,12,9,4,2,4,5,4,2],
 115);
 
 // Edge Data
 findEdges();
 
 function findEdges() : void
 {	
  //Apply Smoothing Filter
  bmd.lock();
  bmd.applyFilter(bmd, bmd.rect, new Point(0, 0), myGausianFilter);
 
  //Create New Bitmap to hold edge data
  ourEdgeData = new BitmapData(bmd.width, bmd.height, false);
 
  var gx : int;;
  var gy : int;
  var gray : uint;
 
  //Loop through original data and calculate edges
  for(var w : int = 0;w < bmd.width; w++)
  {
   for(var h : int = 0;h < bmd.height; h++)
   {
    pV0 = int(bmd.getPixel(w, h - 1)/ uint(0xffffff)*255);
    pV45 = int(bmd.getPixel(w + 1, h - 1)/ uint(0xffffff)*255);
    pV90 = int(bmd.getPixel(w + 1, h)/ uint(0xffffff)*255);
    pV35 = int(bmd.getPixel(w + 1, h + 1)/ uint(0xffffff)*255);
    pV80 = int(bmd.getPixel(w, h + 1)/ uint(0xffffff)*255);
    pV225 = int(bmd.getPixel(w - 1, h + 1)/ uint(0xffffff)*255);
    pV270 = int(bmd.getPixel(w - 1, h)/ uint(0xffffff)*255);			
    pV315 = int(bmd.getPixel(w - 1, h - 1)/ uint(0xffffff)*255);	 
 
    gx = (pV45+(pV90*2)+pV35)-(pV315+(pV270*2)+pV225);
    gy = (pV315+(pV0*2)+pV45)-(pV225+(pV80*2)+pV35);
    gray = Math.abs(gx) + Math.abs(gy);
 
    // Check to see if values aren't our of bounds
    if(gray > 255)
     gray = 255;
 
    if(gray < 0)
	  gray = 0;
 
    // Build New Pixel
    newPixelValue = (gray << 16)+(gray << 8)+(gray);
 
    // Copy New Pixel Into Edge Data Bitmap
    ourEdgeData.setPixel(w, h, newPixelValue);	
   }	
  }
 
  bmd.unlock();
 }
 
 function getGray(pixelValue : uint) : uint
 {
  var red : uint = (pixelValue >> 16 & 0xFF) * 0.30;
  var green : uint = (pixelValue >> 8 & 0xFF) * 0.59;
  var blue : uint = (pixelValue & 0xFF) * 0.11;
 
  return (red + green + blue);
 }
 
 _bmp3.bitmapData = ourEdgeData;
 
}

FDT compile ant on shortcut

What i missed in fdt was compling the last build on shortcut. As you might imagine i’m not a friend of reading eclipse preferences. So i asked a nic guy from powerflasher yesterday ;)

eclipse -> preferences -> general -> keys -> run last launched external tool

duplicate movieclip in as3

well this snippet won’t work for every case, but you can do it like this:

import flash.display.Sprite;
 
public class ExClip extends Sprite
{
	private var _param : String;
 
	public function ExClip(param : String)
	{
		_param = param;
	}
 
	public function clone() : ExClip
	{
		var ret : ExClip = new ExClip(_param);
 
		return ret;
	}
 
}
 
// call
var tmp1 : ExClip = new ExClip("param1");
var tmp2 : ExClip = tmp1.clone();

Works fine for me.
So long

Flash flv metadata error #1069

Working with flvs I got that error

“Error #1069 onMetaData for flash.net.NetStream not found”

Here’s the fix.

var nc : NetConnection = new NetConnection();
nc.connect(null);
var ns : NetStream = new NetStream(nc);
var vid : Video = new Video();
 
var listener : Object = new Object();
 
// this is optional
//
listener.onMetaData = function(infoObject : Object):void
{
	trace("onMetaData");
	var key : String;
	for (key in infoObject)
	{
		trace(key + ": " + infoObject[key]);
	}
}
 
// this is optional
//
listener.onCuePoint = function(infoObject : Object):void
{
	trace("onCuePoint");
	var key : String;
	for (key in infoObject)
	{
		trace(key + ": " + infoObject[key]);
	}
}
 
// this is "the magic"
//
ns.client = listener;
ns.play("videos/vid2.flv");
vid.attachNetStream(ns);
addChild(vid);

So long

Bitmapsmoothing – glätten via AS3

When you work with embed smoothing (glätten) images works with this snippet:

[Embed(source="pathto/image.png")]
private var _imgName : Class;
 
...
 
var tmpSpr : Sprite = new Sprite();
var tmpBmp : Bitmap = new _imgName as Bitmap;
 
tmpBmp.smoothing = true;
 
tmpSpr.addChild(tmpBmp);

Flashtip : Zoom in a clip to a specific point

Imagine you have to zoom in a mc on a specific point.
This math snippet works fine for me (I used TweenLite in my Code):

var tmpEndX : Number = ((spr.width)-(width*scaleFact))/2;
var tmpEndY : Number = ((spr.height)-(spr.height*scaleFact))/2;
 
var tmpXShift : Number = (mouseX-(width/2))*scaleFact;
var tmpYShift : Number = (mouseY-(spr.height/2))*scaleFact;
 
TweenMax.to(this, 0.5,{scaleX : scaleFact});
TweenMax.to(this, 0.5,{scaleY : scaleFact});
TweenMax.to(this, 0.5,{x : tmpEndX - tmpXShift});
TweenMax.to(this, 0.5,{y : tmpEndY - tmpYShift});

Demo and full Class here