stage.addEventListener(KeyboardEvent.KEY_DOWN, keyboardListener);
function keyboardListener(event:KeyboardEvent):void {
trace("event.keyCode: " + event.keyCode);
}
Thursday, May 21, 2009
Flash AS2 - Detect Keyboard press
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if (Key.getCode() == Key.ENTER) {
trace("enter is pressed");
}
}
Key.addlistener(keyListener);
keyListener.onKeyDown = function() {
if (Key.getCode() == Key.ENTER) {
trace("enter is pressed");
}
}
Key.addlistener(keyListener);
Saturday, May 16, 2009
AS3 - crossdomain explanation
In AS3, crossdomain.xml must be placed on the server that provided the service itself, for example, I want to get the rss feed from lifehacker.com, when I do the URLRequest to http://feeds.gawker.com/lifehacker/full flash will request http://feeds.gawker.com/crossdomain.xml.
I guest that should explain how AS3 uses the crossdomain.xml to do crossdomain stuffs :)
I guest that should explain how AS3 uses the crossdomain.xml to do crossdomain stuffs :)
Flash AS2 - Pixelation effect
Recently I found out this method to put pixel effect to your movieclip in AS2. Here goes the code:
//speed is in seconds
//_mc is the movieclip you want to apply pixel effect to
//pixel_from is the number of pixel to start, 1 is the original pixel size for every image
//pixel_target is the number of pixel to display at result
function pixelation(_mc:MovieClip, pixel_from:Number, pixel_target:Number, speed:Number) {
this.createEmptyMovieClip("pixelated_mc", 1 );
_mc._visible = false;
pixelated_mc._x = _mc._x;
pixelated_mc._y = _mc._y;
var pixelSize = pixel_from;
onEnterFrame = function(){
if (pixel_target > pixel_from) {
if (pixelSize >= pixel_target) {
pixelSize = pixel_target;
}
} else if (pixel_target < pixelsize =" pixel_target;" bitmapdata =" new" scalematrix =" new" _width =" _mc._width;" _height =" _mc._height;"> pixel_from) {
if (pixelSize == pixel_target) {
delete onEnterFrame;
}
pixelSize += (pixel_from*25)/speed;
} else if (pixel_target < pixel_from) {
if (pixelSize == pixel_target) {
delete onEnterFrame;
}
pixelSize -= (pixel_target*25)/speed;
} else {
pixelSize = pixel_target;
delete onEnterFrame;
}
}
}
// must try!
//speed is in seconds
//_mc is the movieclip you want to apply pixel effect to
//pixel_from is the number of pixel to start, 1 is the original pixel size for every image
//pixel_target is the number of pixel to display at result
function pixelation(_mc:MovieClip, pixel_from:Number, pixel_target:Number, speed:Number) {
this.createEmptyMovieClip("pixelated_mc", 1 );
_mc._visible = false;
pixelated_mc._x = _mc._x;
pixelated_mc._y = _mc._y;
var pixelSize = pixel_from;
onEnterFrame = function(){
if (pixel_target > pixel_from) {
if (pixelSize >= pixel_target) {
pixelSize = pixel_target;
}
} else if (pixel_target < pixelsize =" pixel_target;" bitmapdata =" new" scalematrix =" new" _width =" _mc._width;" _height =" _mc._height;"> pixel_from) {
if (pixelSize == pixel_target) {
delete onEnterFrame;
}
pixelSize += (pixel_from*25)/speed;
} else if (pixel_target < pixel_from) {
if (pixelSize == pixel_target) {
delete onEnterFrame;
}
pixelSize -= (pixel_target*25)/speed;
} else {
pixelSize = pixel_target;
delete onEnterFrame;
}
}
}
// must try!
Monday, May 4, 2009
Flash AS3 - Using Caurina tweener
//Download the class here: http://code.google.com/p/tweener/downloads/list
import caurina.transitions.Tweener;
Tweener.addTween(movieClip, { alpha: 1, time: 10, onComplete: function(){}});
//documentation here: http://hosted.zeh.com.br/tweener/docs/en-us/
import caurina.transitions.Tweener;
Tweener.addTween(movieClip, { alpha: 1, time: 10, onComplete: function(){}});
//documentation here: http://hosted.zeh.com.br/tweener/docs/en-us/
Subscribe to:
Posts (Atom)