Thursday, June 3, 2010

Phythagorean Theorem - Distance Formula

Sum of the Squares of the two legs of a right triangle is equal to the square of the hypotenuse.

A^2 + B^2 = C^2


var dist:Number;
var circle:Circle;

function onStageEnter(event) {
var dx:Number = event.target.x - mouseX;
var dy:Number = event.target.y - mouseY;
dist = Math.sqrt(dx*dx + dy*dy);
event.target.alpha = 1-(dist/250);
distText.text = String(dist);
distText.x = mouseX;
distText.y = mouseY+20;
}

for (var i:int = 1; i<=7; i++) {

 for (var j:int = 1; j<=5; j++) {

  circle = new Circle();
  circle.x = (i*circle.width)-circle.width;
  circle.y = (j*circle.height)-circle.height;
  circle.addEventListener(Event.ENTER_FRAME, onStageEnter);
  addChild(circle);
 }
}



Friday, May 28, 2010

Math - Rotate MovieClip to towards Mouse

Tuesday, April 27, 2010

Numeric Puzzle Game !

You have a surprise at the end of the game !!

Tuesday, March 9, 2010

Learn Actionscirpt Techniques - ColorPicker Gradient



The ColorPicker component displays a list of one or more swatches from which the user can select a color.

By default, the component displays a single swatch of color on a square button. When the user clicks this button, a panel opens to display the complete list of swatches.

// Here is the Source Code

var startHex;
var endHex;
var spacing:int = 25;
var noOfBoxes:int = 13;
function fadeHex(ratio) {
var r = startHex >> 16;
var g = startHex >> 8 & 0xFF;
var b = startHex & 0xFF;
r += ((endHex >> 16 & 0xFF)-r)*ratio;
g += ((endHex >> 8 & 0xFF)-g)*ratio;
b += ((endHex & 0xFF)-b)*ratio;
return (r << 16 | g << 8 | b);
}
function drawSquare(x, y, color) {
graphics.beginFill(color);
graphics.moveTo(x,y);
graphics.lineTo(x+50,y);
graphics.lineTo(x+50,y+50);
graphics.lineTo(x,y+50);
graphics.lineTo(x,y);
}
function colorChange(e:Event) {
var cp:ColorPicker = e.target as ColorPicker;
if (cp==cp1) {
startHex = "0x"+e.target.hexValue ;
} else {
endHex = "0x"+e.target.hexValue;
}
for (var i = 0; i
var ratio = i/noOfBoxes;
var xx = spacing+(i*50);
var yy = 70;
var nowColor = fadeHex(ratio);
drawSquare(xx,yy,nowColor);
}
}
cp1.selectedColor = 0x990000;
cp2.selectedColor = 0x000000;
cp1.addEventListener(Event.CHANGE, colorChange);
cp2.addEventListener(Event.CHANGE, colorChange);
cp1.addEventListener(Event.RENDER, colorChange);
cp2.addEventListener(Event.RENDER, colorChange);

Monday, March 8, 2010

AS3 Naming Conventions

Use precise, meaningful, contextually relevant names that are as descriptive as possible. Limit the use of unnecessary abbreviations.

Example: defaultImagePreview
NOT: dfltImgPrv


Start each instance name with a lowercase letter, and intercap the remaining words.

Examples: menuItem, sectionTitle

Apply the same conventions to variable names.

Examples: accountNumber, startingPoint, currentProductName

Begin a class name with an uppercase letter. Write class names in mixed case when it’s a compound or concatenated word. Keep package names as short as possible, using reverse domain naming conventions.

Examples: com.client.project.component.ClassName

Name functions and methods in the form of verbs, since they perform actions.

Examples: getUserName(), calculateTaxes(), createSubMenu()

Name booleans with an appropriate, positive prefix, such as “is”, “has”, “can”, or “should”, for an easier determination between true and false.

Examples: isSoundOn, isFinished, isOpen, isLoggedIn, hasLicense, canEvaluate

Use complement names for complement entities: get/set, add/remove, create/destroy, start/stop, insert/delete, increment/decrement, old/new, begin/end, first/last, up/down, min/max, next/previous, open/close, show/hide.

Examples: getUserName, setUserName
addThumbnailImage, removeThumbnailImage
showAnimation, hideAnimation


Private variable names may be prefixed with an underscore or $ symbol as long as consistency is maintained.

Thirukkural