A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: zoom mc_1 to center of reference point mc_2?

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    12

    Question zoom mc_1 to center of reference point mc_2?

    I am building a map app that allows you to drag a map around the screen and it is masked to only allow a portion of it to be seen as you zoom in. For zoom, I can only think of scaling the mc_1 (which is the map). Since my stage is larger than my map viewable area, i have placed a mc_2 as the background to the map. mc_2 is the "stage" for mc_1. So mc_1 is above mc_2.

    I want to enlarge mc_1 by easing out...but don't know how to scale it where it looks like a real zoom effect. I figured I would just have the user click a + button and it would scale it to a predetermined size. Any ideas how to ease it in/out?

    Main question:
    Lets say my map was of the united states and I drag the map around my window and Texas is in the center point of the mc_2. How do I zoom in on Texas, instead of it just scaling mc_1?

    I would greatly appreciate any assistance rendered. Thanks!

  2. #2
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    you can approixmate the registration point of the scaling movieclip to the desired location. so lets say texas, in relation to the movieclip , is at x : 500 , y : 250. You would want to set the registration point to 500 , 250 internally to the scaling clip. That way when you scale it will scale from that point up. Depending on how you have things nested you might need to do some globalToLocal point conversions , but it shouldnt be too hard.

  3. #3
    Junior Member
    Join Date
    Nov 2009
    Posts
    12
    Quote Originally Posted by AttackRabbit View Post
    you can approixmate the registration point of the scaling movieclip to the desired location. so lets say texas, in relation to the movieclip , is at x : 500 , y : 250. You would want to set the registration point to 500 , 250 internally to the scaling clip. That way when you scale it will scale from that point up. Depending on how you have things nested you might need to do some globalToLocal point conversions , but it shouldnt be too hard.
    I don't understand globalToLocal point conversions. Do you know of any tutorials on the subject?

  4. #4
    Junior Member
    Join Date
    Jun 2008
    Posts
    25
    http://blog.greensock.com/tweenlite/

    may this site can help u if u want to show some simple zoom in zoom out effect.

  5. #5
    Senior Member
    Join Date
    May 2004
    Posts
    226
    I recently prototyped something similar. It's probably not exactly what you're after but should get you close.

    doubleclick to zoom in.
    shift+doubleclick to zoom out.
    click and drag to move image.
    shift+click and drag to move mask.

    PHP Code:
    import fl.transitions.*;
    import fl.transitions.easing.*;

    var 
    loader:Loader = new Loader();
    loader.load( new URLRequest"http://www.loscoltrahues.com/01-00-000%20Herramientas%20Camera%20Department%20-%20Camera%20Department%20Tools/01-01-000%20Ajustes%20y%20Calibracion%20-%20Adjustments%20and%20Calibration/dSam%20Depth%20of%20Field%20Test%20Chart.JPG" ) );

    var 
    image:Sprite = new Sprite();
    image.addChildloader );

    var 
    maskSprite:Sprite = new Sprite();
    maskSprite.graphics.beginFill);
    maskSprite.graphics.drawEllipse00400400 );
    maskSprite.graphics.endFill();

    image.mask maskSprite;
    image.cacheAsBitmap true;
    image.doubleClickEnabled true;
    image.mouseChildren false;
    image.scaleX 0.5;
    image.scaleY 0.5;

    var 
    tweenX:Tween = new Tweenimage"x"Regular.easeOutimage.ximage.x1true );
    var 
    tweenY:Tween = new Tweenimage"y"Regular.easeOutimage.yimage.y1true );
    var 
    tweenScaleX:Tween = new Tweenimage"scaleX"Regular.easeOutimage.scaleXimage.scaleX1true );
    var 
    tweenScaleY:Tween = new Tweenimage"scaleY"Regular.easeOutimage.scaleYimage.scaleY1true );

    var 
    scaleInc:Number 2;
    var 
    scaleMin:Number .0625;
    var 
    scaleMax:Number 4;

    function 
    onImageDoubleClicke:MouseEvent ):void {
        var 
    scale:Number e.shiftKey image.scaleX scaleInc image.scaleX scaleInc;
        
    scale Math.minMath.maxscalescaleMin ), scaleMax );
        
        var 
    offsetX:Number = ( maskSprite.width +  maskSprite.) - ( image.mouseX scale );
        var 
    offsetY:Number = ( maskSprite.height +  maskSprite.) - ( image.mouseY scale );
        
        
    updateTweentweenXimage.xoffsetX );
        
    updateTweentweenYimage.yoffsetY );
        
    updateTweentweenScaleXimage.scaleXscale );
        
    updateTweentweenScaleYimage.scaleYscale );
    }
    function 
    updateTweentween:Tweenbegin:Numberfinish:Number ):void {
        
    tween.stop();
        
    tween.begin begin;
        
    tween.finish finish;
        
    tween.start();
    }
    function 
    onImageStartDrage:MouseEvent ):void {
        
    e.shiftKey maskSprite.startDrag() : image.startDrag();
        
        
    stage.addEventListenerMouseEvent.MOUSE_UPonImageStopDrag );
    }
    function 
    onImageStopDrage:MouseEvent ):void {
        
    stage.removeEventListenerMouseEvent.MOUSE_UPonImageStopDrag );
        
    stopDrag();
    }
    image.addEventListenerMouseEvent.DOUBLE_CLICKonImageDoubleClickfalse0true );
    image.addEventListenerMouseEvent.MOUSE_DOWNonImageStartDragfalse0true );
    addChildimage ); 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center