# \[FMX\] Scripted movement

**URL:** <https://forum.kirupa.com/t/fmx-scripted-movement/12042>\
**Category:** flash\
**Created:** [January 25, 2003, 10:21pm UTC](https://forum.kirupa.com/t/fmx-scripted-movement/12042 "2003-01-25T22:21:03Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![DDD](https://avatars.discourse-cdn.com/v4/letter/d/9fc348/32.png) [@DDD](https://forum.kirupa.com/u/DDD)\
**Post date:** [January 25, 2003, 10:21pm UTC](https://forum.kirupa.com/t/fmx-scripted-movement/12042/1 "2003-01-25T22:21:03Z")

</div>

I need a little help…Okay I have a flash movie the canvas is 440x200. Okay I have a graphic which is 880x200 and is centered vertically and horizantally. So some of the movie is off stage. Now what I am trying to make happen is when the mouse is on the left side of movie the movie will move to the right revealing the rest of the movie which is not shown because it is off stage. Likewise if you mouse over the right side the image will move to the left revealing the off stage content. The catch is I do not want it to go beyond the length of the movie. I have spent way too much time trying to get this one. Could someone help me please. Actionscript is really hard for me…Dont know why:q:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 25, 2003, 10:54pm UTC](https://forum.kirupa.com/t/fmx-scripted-movement/12042/2 "2003-01-25T22:54:49Z")

</div>

I’m not sure excatly what you are trying to do but:

this.onMouseMove=funtion(){  
picture.\_x =\_xmouse;  
}

???

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 25, 2003, 11:04pm UTC](https://forum.kirupa.com/t/fmx-scripted-movement/12042/3 "2003-01-25T23:04:46Z")

</div>

As an add on (make your image a movie clip)

onClipEvent(mouseMove) {  
this.\_x =\_xmouse;  
if (this.\_x \>= howFarYouWantToGoRight) {  
this.\_x = howFarYouWantToGoRIght;  
}  
if (this.\_x \<= howFarYouWantToGoLeft) {  
this.\_x = howFarYouWantToGoLeft;  
}  
}

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 25, 2003, 11:44pm UTC](https://forum.kirupa.com/t/fmx-scripted-movement/12042/4 "2003-01-25T23:44:28Z")

</div>

> As an add on (make your image a movie clip)

Do I add your code to Rynoes??

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 25, 2003, 11:47pm UTC](https://forum.kirupa.com/t/fmx-scripted-movement/12042/5 "2003-01-25T23:47:32Z")

</div>

Use lost’s code and change the howFarYouWantToGo to the correct numbers

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 25, 2003, 11:50pm UTC](https://forum.kirupa.com/t/fmx-scripted-movement/12042/6 "2003-01-25T23:50:46Z")

</div>

Oh yeah forgot to mention. I was trying to get it to slide to the appropriate side. As an added bonus I would like for it to slide back in its original place when the mouse is no longer there.

By the way lost your code worked, but I forgot to be more clear on what I was after.

Hey Rynoe you need me to explain in greater detail??

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 25, 2003, 11:54pm UTC](https://forum.kirupa.com/t/fmx-scripted-movement/12042/7 "2003-01-25T23:54:46Z")

</div>

Well if I am thinking correctly and your image takes up the whole stage, there is no way to detect if the mouse is off or not. Even hitTest won’t work :-\

I might be overlooking something though.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 26, 2003, 12:08am UTC](https://forum.kirupa.com/t/fmx-scripted-movement/12042/8 "2003-01-26T00:08:40Z")

</div>

onClipEvent(mouseMove) {  
position=(\_xmouse-440)\*-1;  
this.\_x = position;  
}

since 880 is exactly twice 440

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 26, 2003, 12:18am UTC](https://forum.kirupa.com/t/fmx-scripted-movement/12042/9 "2003-01-26T00:18:07Z")

</div>

Okay hhhmmmm… Basically I need to detect if the mouse is on the left or right side of the movie. Image a vertical line going though the horizantal middle f the movie. If the mouse is on the left side of that line slide the movie to the right, If it is on the right side of the line slide my movie to the left. I can picture what I want to happen but I cannot code it. ANd if the mouse is not in the movie at all return it to the middle of the stage.

Oh yeah thanks for the help thus far… I will give credit to you on this little proj…or whoever helps

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 26, 2003, 12:24am UTC](https://forum.kirupa.com/t/fmx-scripted-movement/12042/10 "2003-01-26T00:24:47Z")

</div>

But see, that is the thing. The clip takes up the whole stage, so by the time your mouse is off the clip it is out of the movie, so it won’t be able to be set to go back to the original spot.

You could probably use hitTest to determine if the \_xmouse is within a certain contained area.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 26, 2003, 12:29am UTC](https://forum.kirupa.com/t/fmx-scripted-movement/12042/11 "2003-01-26T00:29:02Z")

</div>

ok

onClipEvent(mouseMove) {  
if (\_xmouse \>300) {  
this.\_x = 0;  
}  
else if(\_xmouse\<200){  
this.\_x = 440;  
else{  
this.\_x=220;  
}  
}

200 and 300 are estimates

is this what you are looking for?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 26, 2003, 12:32am UTC](https://forum.kirupa.com/t/fmx-scripted-movement/12042/12 "2003-01-26T00:32:49Z")

</div>

I came up with this…

```php
onClipEvent(mouseMove) {
	if (_root._xmouse<=90 && _root._xmouse>=540 && _root._ymouse<=390 && _root._ymouse>=10) {
		trace("in");
	} else {
		trace("out");
	}
};

```

The above script assumes your movie is 550x400 and sets up a 10px border around your whole movie. If your mouse is inside that border it will trace “in” and if it is outside that border it will trace “out”.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 26, 2003, 12:57am UTC](https://forum.kirupa.com/t/fmx-scripted-movement/12042/13 "2003-01-26T00:57:52Z")

</div>

Hey lost and rynoe they both did not work. I think maybe my explanation is not good. I dont know how to explain it better. I can visualize it but I cannot program it.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 26, 2003, 1:44am UTC](https://forum.kirupa.com/t/fmx-scripted-movement/12042/14 "2003-01-26T01:44:50Z")

</div>

I tested this and it works for me… I think it might be messing up because of furum so notepad below

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 26, 2003, 5:15am UTC](https://forum.kirupa.com/t/fmx-scripted-movement/12042/15 "2003-01-26T05:15:02Z")

</div>

Okay rynoe that worked thanks man. And I actually understand the code. Now I am trying to control the speed at which the movie shifts any ideas?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 26, 2003, 5:19am UTC](https://forum.kirupa.com/t/fmx-scripted-movement/12042/16 "2003-01-26T05:19:56Z")

</div>

I KNEW you were gonna ask me that!!!  
yes I have ideas…  
But lostinbeta really has the bead on that one.  
It’s a math thing check [this](http://hurlburts.com/what.html) for an example.

But I am really glad I could help!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 26, 2003, 5:27am UTC](https://forum.kirupa.com/t/fmx-scripted-movement/12042/17 "2003-01-26T05:27:03Z")

</div>

You could use the easing formula…

[http://www.kirupa.com/developer/mx/followease.asp](http://www.kirupa.com/developer/mx/followease.asp)

(if I am understanding correctly)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 26, 2003, 5:47am UTC](https://forum.kirupa.com/t/fmx-scripted-movement/12042/18 "2003-01-26T05:47:56Z")

</div>

I have come to the realization I suck at AS. I have spent the whole day on this simple thing and cannot get it. I think I am gonna give up on it. I am just not getting it. I really hate to keep leanin on folks for knowledge. If one of you have a .fla I can study that would be cool. (or cut and paste)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 27, 2003, 1:38am UTC](https://forum.kirupa.com/t/fmx-scripted-movement/12042/19 "2003-01-27T01:38:37Z")

</div>

bump…i still need help…pleez…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 27, 2003, 2:33am UTC](https://forum.kirupa.com/t/fmx-scripted-movement/12042/20 "2003-01-27T02:33:56Z")

</div>

assuming you’re image is inside an mc and the registry point is at the middle of the image:

```auto

_root.onEnterFrame = function () {
	if (_root._xmouse < 220) {
		if (_root.imageInstanceName._x < 400) {
			_root.imageInstanceName._x += 2
		}
	} else if (_root._xmouse > 220) {
		if (_root.imageInstanceName._x > 40) {
			_root.imageInstanceName._x -= 2
		}
	}
}

```

[size=1]**[EDIT]**[/size]  
forgot the fla

[Next page](https://forum.kirupa.com/t/fmx-scripted-movement/12042.md?page=2)
