Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Page 1 of 3 123 LastLast
Results 1 to 15 of 43

Thread: Movie image in opposite direction

  1. #1

    Movie image in opposite direction

    Does anyone know the algorithm used in this image panner
    http://flashden.net/item/image-viewer/8883

    How to move the image in the opposite direction of mouse.

  2. #2
    238
    posts
    Registered User
    Code:
    var img:Sprite; //zoomed image
    stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
    function onMove(m:MouseEvent) : void {
         var mx:Number = stage.mouseX;
         var my:Number = stage.mouseY;
         var dx:Number = mx - tempx;
         var dy:Number = my - tempy;
         tempx = mx;
         tempy = my;
         if( (mx > 0) && (mx < img.width) ) img.x -= dx;
         if( (my > 0) && (my < img.height) ) img.y -= dy;
    }
    something like that would probably do the trick

  3. #3
    238
    posts
    Registered User
    ^^forgot to declare tempx and tempy, oops

  4. #4
    Would tempx and tempy just be a number?
    I tried that math out and it just makes it disappears. Its probably off the stages viewing area.
    Last edited by waverider303; May 3rd, 2009 at 12:54 AM.

  5. #5
    238
    posts
    Registered User
    try this?

    var img:Sprite; //zoomed image
    stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
    function onMove(m:MouseEvent) :
    void {
    var mx:
    Number = stage.mouseX;
    var my:
    Number = stage.mouseY;
    var dx:
    Number = ( (mx – tempx) > 1) ? 1: -1;
    var dy:
    Number = ( (my – tempy) > 1) ? 1: -1;
    tempx = mx;
    tempy = my;
    if( (mx > 0) && (mx < img.width) ) img.x -= dx;
    if( (my > 0) && (my < img.height) ) img.y -= dy;
    }

  6. #6
    var dx:Number = ( (mx – tempx) > 1) ? 1: -1;
    if( (mx > 0) && (mx < img.width) ) img.x -= dx;
    IS this AS3? why does the if statement not have { }. What is the ? for in the statement?

  7. #7
    238
    posts
    Registered User
    yeah it's as3.

    in an if statement, you don't need the braces if there is only one line. if i needed to do something else besides just "img.x -= dx" i would have to use braces.

    the ? is a conditional operator. it's basically an if/then statement all in one line. it's a little faster, but really just more elegant.

    Code:
    var dx:Number = ( (mx - tempx) > 1) ? 1: -1;
    is equivalent to:

    Code:
    var dx:Number;
    if( (mx-tempx) > 1){
         dx = 1;
    }else{
         dx = -1;
    }
    so really it's just a space saver

  8. #8
    Ok a gave it a try it is moving in the right place. One problem is it only moves to the right it wont come back to the left. Would it be an anchor point problem? I currently have it in the middle.

  9. #9
    238
    posts
    Registered User
    edit: yes it should be anchored at top left

  10. #10
    have you given this math a try?
    It only moves towards the bottom right. So the upper lefthand corner is the only part of the stage that will make it move. in the bottom right corners it doesnt move.
    Last edited by waverider303; May 3rd, 2009 at 01:25 AM.

  11. #11
    238
    posts
    Registered User
    no my laptop died today i don't have flash on this computer. is it not working?

  12. #12
    no Dice. It moves pretty smoothly it just moves down and to the right. It doesnt move up or to the left.
    Last edited by waverider303; May 3rd, 2009 at 01:52 AM.

  13. #13
    238
    posts
    Registered User
    oh, sorry.

    var dx:Number = ( (mx – tempx) > 1) ? 1: -1;
    var dy:
    Number = ( (my – tempy) > 1) ? 1: -1;

    should be

    var dx:Number = ( (mx – tempx) > 0) ? 1: -1;
    var dy:
    Number = ( (my – tempy) > 0) ? 1: -1;

  14. #14
    Unfortunately its the same. Here is a link to see in real time the demo. Thanks for helping me through this. I bet we will get it working soon!

    Link: http://www.csteelmedia.com/flash/test.html

  15. #15
    238
    posts
    Registered User
    can you post the code you're using for this? for me, its always moving even if the mouse isn't moving

Page 1 of 3 123 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012