This Blog contains About Action script 3.0 Variables, Data types, Access specifies, Keywords, Operators, Conditional statements, Control statements, Arrays (Indexed, Associative, Multidimensional, Cloning), Functions, Symbols, Movie clips (Transformation point, Registration point, Loading images), Buttons, Events (Key board, Mouse, Timer, XML)Pre- defined function :- Random, Hit test object, Drag and drop, Sort, Loader, Tween,URL Loader, Video components, Audio Components, Sound Channel.
Friday, 8 March 2013
zoom in, out and drag isometric land in as3
Code :-
=====
land.addEventListener(MouseEvent.MOUSE_DOWN,moveland);
land.addEventListener(MouseEvent.MOUSE_UP,releaseland);
land.buttonMode = true;
function moveland(event:Event):void
{
event.target.startDrag();
}
function releaseland(event:Event):void
{
event.target.stopDrag();
}
import fl.transitions.*;
import fl.transitions.easing.*;
import fl.motion.easing.*;
var factorZoom:Number;
stage.addEventListener(MouseEvent.MOUSE_WHEEL ,onclick);
factorZoom=1;
function onclick(e:MouseEvent) {
if (e.delta>0) {
factorZoom=factorZoom+0.01;
trace(factorZoom);
} else if (e.delta<0) {
factorZoom=factorZoom-0.01;
}
imageToZoom();
}
function imageToZoom():void {
var overPixelX:Number=land.mouseX;
var overPixelY:Number=land.mouseY;
//
land.scaleX=land.scaleY=factorZoom;
var pixelDifferenceX:Number = (overPixelX - land.mouseX) * factorZoom;
var pixelDifferenceY:Number = (overPixelY - land.mouseY) * factorZoom;
//
var nextX:Number=land.x-pixelDifferenceX;
land.x=checkNewX(nextX);
//
var nextY:Number=land.y-pixelDifferenceY;
land.y=checkNewY(nextY);
}
function checkNewY(checkY:Number):Number {
if (land.height<600) {
return (600 - land.height) / 2;
}
if (checkY>0) {
checkY=0;
} else if (checkY + land.height < 600) {
checkY=600-land.height;
}
return checkY;
}
function checkNewX(checkX:Number):Number {
if (land.width<800) {
return (800 - land.width) / 2;
}
if (checkX>0) {
checkX=0;
} else if (checkX + land.width < 800) {
checkX=800-land.width;
}
return checkX;
}
Out Put :-
=======
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment