# Error: panning over movie clip both Horiz.&Vert

**URL:** https://forum.kirupa.com/t/error-panning-over-movie-clip-both-horiz-vert/326973
**Category:** Uncategorized
**Created:** [January 27, 2012, 2:22am UTC](https://forum.kirupa.com/t/error-panning-over-movie-clip-both-horiz-vert/326973 "2012-01-27T02:22:10Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![mufflekid](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@mufflekid](https://forum.kirupa.com/u/mufflekid)
#### Post date: [January 27, 2012, 2:22am UTC](https://forum.kirupa.com/t/error-panning-over-movie-clip-both-horiz-vert/326973/1 "2012-01-27T02:22:10Z")

</div>

So I found this code that lets me pan over a movie clip horizontally.

```auto

import fl.transitions.Tween;
import fl.motion.easing.*;
import fl.transitions.TweenEvent;

var workspageTween:Tween

stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoved)

function mouseMoved(e:MouseEvent)
{
    var xPercent = mouseX / stage.stageWidth;

    var newXPos = (stage.stageWidth - workspage.width) * xPercent;
    workspageTween = new Tween(workspage, "x", Circular.easeOut, workspage.x, newXPos, 1, true);
}

```

And I wanted to incorporate the Y direction, too, so I could pan in all directions. So now it looks like this:

```auto

import fl.transitions.Tween;
import fl.motion.easing.*;
import fl.transitions.TweenEvent;

var workspageTween:Tween

stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoved)

function mouseMoved(e:MouseEvent)
{
    var xPercent = mouseX / stage.stageWidth;
    var yPercent = mouseY / stage.stageHeight;
    var newXPos = (stage.stageWidth - workspage.width) * xPercent;
    workspageTween = new Tween(workspage, "x", Circular.easeOut, workspage.x, newXPos, 1, true);
    var newYPos = (stage.stageHeight - workspage.height) * yPercent;
    workspageTween = new Tween(workspage, "y", Circular.easeOut, workspage.y, newYPos, 1, true);
}

```

While that does work, it’s been giving me “Error #1009: Cannot access a property or method of a null object reference. at allbuttons1920EXP\_fla::MainTimeline/mouseMoved()[allbuttons1920EXP\_fla.MainTimeline::frame165:24]” And is probably why I’m getting another glitch (that, at first, didn’t seem relevant to this).

Frame 165:24 refers to this line from above:

```auto
var newXPos = (stage.stageWidth - workspage.width) * xPercent;

```

I think it has to do with the fact that I just copypasta’d the lines with the x bits and replaced them with y.

So what is the proper way to write this code so that it incorporates both X and Y?

I have a feeling this is probably something obvious to someone who learned as3 properly from the ground up, haha…
