The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

# Thread: Movie image in opposite direction

1. 65
posts
Registered User

## 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. 238
posts
Registered User
Code:
```var img:Sprite; //zoomed image
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. 238
posts
Registered User
^^forgot to declare tempx and tempy, oops

4. 65
posts
Registered User
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. 238
posts
Registered User
try this?

var img:Sprite; //zoomed image
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. 65
posts
Registered User
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. 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. 65
posts
Registered User
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. 238
posts
Registered User
edit: yes it should be anchored at top left

10. 65
posts
Registered User
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. 238
posts
Registered User
no my laptop died today i don't have flash on this computer. is it not working?

12. 65
posts
Registered User
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. 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. 65
posts
Registered User
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!

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 Last