actionscript 3 - AS3: Scale movieclip at another movieclips position? -


i'm trying scale base image based on movieclip's x , y position? base image image mc.

infoiconcompfit.addeventlistener(mouseevent.roll_over, zoomincompfit); infoiconcompfit.addeventlistener(mouseevent.roll_out, zoomoutcompfit);  function zoomincompfit(event:mouseevent):void {    tweenlite.to(baseimage, 1, {scalex:2, scaley:2}); }  function zoomoutcompfit(event:mouseevent):void {    tweenlite.to(baseimage, 1, {scalex:1, scaley:1}); } 

what mean is; possible scale movieclip @ movieclip's x , y position on stage? want base movieclip scale (zoom in) @ position of movieclip on mouse roll_over zoom out on mouse roll_out.

i zooms in , out on handlers, how zoom @ position relative other mc?

(before) http://www.marketingfanatics.co.za/images/examplenormal.jpg (after) http://www.marketingfanatics.co.za/images/examplezoomedl.jpg

yes can. need write code , have in mind transformation pivot of objects.

/**          * calculate position , dimensions of image zoom.          * @param   img - image animate, need have transformation pivot in top left corner!          * @param   point - point zoom in (or null if zoom out) new center of image          * @param   scale - scale in zoom in          * @param   viewwidth - container width          * @param   viewheight - container height          * @return  object tween engine parameters animate          */         private function centeron(img:displayobject, point:point=null, scale:number=2, viewwidth:number=300, viewheight:number=200):object         {             var r:object;             var mm:matrix = img.transform.matrix;             img.transform.matrix = new matrix();              if (point == null) { // oryginal size                 r = { x: 0, y: 0, width: img.width, height: img.height };             }else { // zoom                 img.scalex = img.scaley = scale;                 point.x *= scale;                 point.y *= scale;                 img.x = -point.x + viewwidth / 2;                 img.y = -point.y + viewheight / 2;                 r = { x: img.x, y: img.y, width: img.width, height: img.height };             }             img.transform.matrix = mm;             return r;         } 

use example:

tweenlite.to(baseimage, 1, centeron(baseimg, new point(100, 150))); //zoom in tweenlite.to(baseimage, 1, centeron(baseimg)); //zoom out centeron(img, new point(200, 135), 4, stage.stagewidth, stage.stageheight); // fit stage size 

remember display object not masked , (zoom near borders) see scene under it!

ps. code tested.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -