Stroep

Just a collection of random works – Mark Knol

Archive for 'Code snippets'

Today I created a googlecode account. Now I can easily share actionscript classes with you guys :)

check it out
http://code.google.com/p/stroep/
..or directly go to the source:
http://code.google.com/p/stroep/source/browse/

Tagged with , , .

Quick post; How to crop a bitmap / displayobject / Movieclip / Sprite or just the stage with Flash/AIR/AS3.

function crop( _x:Number, _y:Number, _width:Number, _height:Number, displayObject:DisplayObject = null):Bitmap
{
var cropArea:Rectangle = new Rectangle( 0, 0, _width, _height );
var croppedBitmap:Bitmap = new Bitmap( new BitmapData( _width, _height ), PixelSnapping.ALWAYS, true );
croppedBitmap.bitmapData.draw( (displayObject!=null) ? displayObject : stage, new Matrix(1, 0, 0, 1, -_x, -_y) , null, null, cropArea, true );
return croppedBitmap;
}
 

Usage:

var myCroppedImage:Bitmap = crop( 100, 100, 200, 200 );
this.addChild ( myCroppedImage );
 

Download

» Download CropUtil class on googlecode.

ps. To save the capture, use the ImageSaver class

Tagged with , .

Just a quick but handy tip I’ve found on this post from smashing magazine.

A lot of people who are using twitter, use tinyURL to create very small links for longer URL’s of blogposts or cool links. Its very powerful solution and cost just a little bit time to create, but you can help ‘the twittering people’ by automatically create the tinyURL-link in your post.
Here’s how you can do this in WordPress. It cost less than 2 minutes too implement :)

Just go to design > theme editor > functions.php and add this function

function getTinyUrl($url) {  
     $tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=".$url);  
     return $tinyurl;  
}
 

Basically you can use this function for every site, but for WordPress it’s handy to use the permalink to create the URL:

In the theme editor > single.php you can add this line where ever you want to show the link to the tidyURL.

<?php  
 $turl = getTinyUrl(get_permalink($post->ID));  
 echo ‘Tiny URL: <a href="’.$turl.‘">’.$turl.‘</a>’;
?>

Tagged with , .

Faster Math.abs() (7)

January 28th, 2009, under actionscript, Code snippets.

Quick post :) This function returns the absolute value of a specified number. This is +/- 24x faster than the regular Math.abs().

public function abs( value:Number ):Number
{
return value < 0 ? -value : value;
}
 

Tagged with .