Instantly share code, notes, and snippets.
Created
August 11, 2010 07:31
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save psyked/518634 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* A Fish Eye Menu in Actionscript 2 | |
* converted by James Ford | |
* | |
* based on A Fish Eye Menu in Actionscript 3 | |
* from shinedraw.com | |
*/ | |
var IMAGES:Array = [ "image1", "image2", "image3", "image4", "image5", "image6", "image7" ]; // images | |
var APP_WIDTH : Number = 550; // Width of this movieclip | |
var APP_HEIGHT : Number = 400; // Height of this movieclip | |
var MARGIN:Number = 15; // Margin between images | |
var IMAGE_WIDTH: Number = 48; // Image width | |
var IMAGE_HEIGHT : Number = 48; // Image height | |
var MAX_SCALE:Number = 3; // Max scale | |
var MULTIPLIER:Number = 60; // Control the effectiveness of the mouse | |
var _images : Array = new Array(); // Store the added images | |
///////////////////////////////////////////////////// | |
// Handlers | |
///////////////////////////////////////////////////// | |
function on_added_to_stage():Void{ | |
// add the images to the stage | |
addImages(); | |
// start the mouse event handler | |
//stage.addEventListener(MouseEvent.MOUSE_MOVE, on_mouse_move); | |
} | |
// because we've got no document class, we need | |
// to start things in a more simple way | |
on_added_to_stage() | |
// mouse event handler | |
//function on_mouse_move():Void{ | |
this.onMouseMove = function():Void { | |
//trace("on_mouse_move") | |
for(var i:Number = 0 ; i < _images.length; i++){ | |
var image : MovieClip = _images[i] //as MovieClip; | |
// compute the scale of each image according to the mouse position | |
var imageScale:Number = MAX_SCALE - Math.min(MAX_SCALE - 1, Math.abs(this._xmouse - (image._x + image._width / 2)) / MULTIPLIER); | |
// resize the image | |
resizeImage(image, IMAGE_WIDTH * imageScale, IMAGE_HEIGHT * imageScale, i, IMAGES.length); | |
} | |
// sort the children according to the _yscale | |
sortChildren(this, "_yscale"); | |
} | |
///////////////////////////////////////////////////// | |
// Public Methods | |
///////////////////////////////////////////////////// | |
///////////////////////////////////////////////////// | |
// Private Methods | |
///////////////////////////////////////////////////// | |
// add the images to the stage | |
function addImages():Void{ | |
for(var i:Number = 0; i < IMAGES.length; i++){ | |
// we can't attach bitmaps in AS2 like we do in AS3, so the bitmaps have been | |
// converted to movieclips and attached that way | |
var imageClass : String = IMAGES[i]; | |
var image : MovieClip = this.attachMovie(imageClass, imageClass, this.getNextHighestDepth()) | |
image.cacheAsBitmap = true; | |
// resize the image | |
resizeImage(image, IMAGE_WIDTH, IMAGE_HEIGHT, i, IMAGES.length); | |
_images.push(image); | |
} | |
} | |
// resize the image | |
function resizeImage(image : MovieClip, imageWidth:Number, imageHeight:Number, index:Number, total : Number):Void{ | |
image._width = imageWidth; | |
image._height = imageHeight; | |
image._y = APP_HEIGHT/2 - image._height/2; | |
image._x = APP_WIDTH/ 2 + (index - (total - 1) / 2) * (MARGIN + IMAGE_WIDTH) - image._width / 2; | |
} | |
// Sort the objects according to the image width | |
function sortChildren(container, criteria:String) : Void { | |
var _numChildren:Number = IMAGES.length//container._numChildren; | |
//no need to sort (zero or one child) | |
if( _numChildren < 2 ) return ; | |
//create an Array to sort children | |
var children:Array = new Array( _numChildren ); | |
var i:Number = -1; | |
while( ++i < _numChildren ) | |
{ | |
children[ i ] = {mc:container.getInstanceAtDepth( i ), num:container.getInstanceAtDepth( i )._yscale}; | |
} | |
//sort by children by the criteria | |
children.sortOn( "num", Array.NUMERIC ); | |
var child : MovieClip; | |
i = -1; | |
while( ++i < children.length ) | |
{ | |
child = MovieClip( children[ i ].mc ); | |
//only set new depth if necessary | |
if( i != container.getInstanceAtDepth(i) ) | |
{ | |
//set their new position | |
child.swapDepths(container.getInstanceAtDepth(i)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment