Thursday, June 4, 2009

jquery - Create rollover image buttons | make rollover image buttons from single function using jquery

//make a duplicate image of each jpg or png and add "_over" behind the filename. Inside the img tag, put class name as "button" png button, and "jpgBtn" for normal jpg buttons

$(document).ready(function() {

if (!$.browser.msie || ($.browser.msie && $.browser.version > 6)) { //if not ie6 png buttons
//png button
$("img.button").hover(
function () {
ori = $(this).attr("src").split(".png");
src = ori[0];
$(this).attr("src",src + "_over.png");
},
function () {
$(this).attr("src",src + ".png");
}
);
}

//jpg button
$("img.jpgBtn").hover(
function () {
ori = $(this).attr("src").split(".jpg");
src = ori[0];
$(this).attr("src",src + "_over.jpg");
},
function () {
$(this).attr("src",src + ".jpg");
}
);

});

jquery - Inserting jquery framework to your html | google host jquery

A simple line of code so that you don't need to host your jquery framework. Let google do that for you :)

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>

Thursday, May 21, 2009

Flash AS3 - Detecting key press | identify Keyboard press | keyCode event

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyboardListener);

function keyboardListener(event:KeyboardEvent):void {
trace("event.keyCode: " + event.keyCode);
}

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);

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 :)

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!

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/