# Senocular 3d tut question

**URL:** <https://forum.kirupa.com/t/senocular-3d-tut-question/42553>\
**Category:** flash\
**Created:** [February 10, 2004, 11:00am UTC](https://forum.kirupa.com/t/senocular-3d-tut-question/42553 "2004-02-10T11:00:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![macneilslt](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@macneilslt](https://forum.kirupa.com/u/macneilslt)\
**Post date:** [February 10, 2004, 11:00am UTC](https://forum.kirupa.com/t/senocular-3d-tut-question/42553/1 "2004-02-10T11:00:28Z")

</div>

In the beginning of sen’s 3d tutorial, there’s an example of 3 guys moving back and forth and resizing so they look as if they are 3d…they move back and fourth with this function:

[AS]

backAndForth = function(){  
this.z += speed\*this.dir;  
if (this.z \> 500){  
this.z = 500;  
this.dir = -1;  
}else if (this.z \< 0){  
this.z = 0;  
this.dir = 1;  
}

```
var scaleRatio = focalLength/(focalLength + this.z);
this._x = origin.x + this.x * scaleRatio;
this._y = origin.y + this.y * scaleRatio;
this._xscale = this._yscale = 100 * scaleRatio;
this.swapDepths(-this.z);

```

};

[/AS]

then they are moved with this:

[AS]  
figureA.onEnterFrame = backAndForth;  
figureB.onEnterFrame = backAndForth;  
figureC.onEnterFrame = backAndForth;  
[/AS]

what i want to do is change the movement function into 2 seperate parts, back and forth, and set it up so you have to click a guy to get him to come foward, then click him again to send him back?

i’ve tried…but it’s not working out, any 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:** [February 10, 2004, 11:14am UTC](https://forum.kirupa.com/t/senocular-3d-tut-question/42553/2 "2004-02-10T11:14:24Z")

</div>

the this.dir variable controls the direction of movement. You can see that the z variable (this.z) gets incremented based on dir.

```auto
this.z += speed*this.dir;

```

so if dir is positive, z goes up by a factor of speed. If it’s negative, z goes down by a factor of speed.

So what you need is to do is add a click behavior that changes that dir variable. This will probably consist of something along the lines of

```auto
onPress = function(){ this.dir = -this.dir; }

```

so that it will reverse or change over the current directional variable of dir. If its positive now, clicking will make it negative and change directions. If negative, it will become positive and, again, change directions.

The only thing left is to keep the clip from continuously going in that same direction indefinitely, i.e. if dir is negative, dont keep moving z back and back and back forever. This can be handled with a simple if condition making sure that z doesnt go greater than or less than its supposed to. This is actually already done in the code you posted with 0 and 500. You just need to take out where dir is changed. That will be handled in your onPress action.

---

<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:** [February 10, 2004, 11:32am UTC](https://forum.kirupa.com/t/senocular-3d-tut-question/42553/3 "2004-02-10T11:32:14Z")

</div>

hmm, i’m not quite sure, i think i understand what your saying, and this is what i have now…but they aren’t moving…even though the z factor should be changing on press

---

<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:** [February 10, 2004, 11:41am UTC](https://forum.kirupa.com/t/senocular-3d-tut-question/42553/4 "2004-02-10T11:41:17Z")

</div>

you didnt assign the onEnterFrames

---

<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:** [February 10, 2004, 11:45am UTC](https://forum.kirupa.com/t/senocular-3d-tut-question/42553/5 "2004-02-10T11:45:00Z")

</div>

would i add that to the main function, or to the individual on key presses?

---

<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:** [February 10, 2004, 12:17pm UTC](https://forum.kirupa.com/t/senocular-3d-tut-question/42553/6 "2004-02-10T12:17:41Z")

</div>

no the ones you deleted and posted in your first post. Those dont go away.

---

<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:** [February 10, 2004, 2:52pm UTC](https://forum.kirupa.com/t/senocular-3d-tut-question/42553/7 "2004-02-10T14:52:05Z")

</div>

Thanks a ton 🙂

---

<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:** [February 10, 2004, 2:55pm UTC](https://forum.kirupa.com/t/senocular-3d-tut-question/42553/8 "2004-02-10T14:55:27Z")

</div>

start their z at any of the maxes. (make sure you set the dir property to go with that)

---

<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:** [February 10, 2004, 3:49pm UTC](https://forum.kirupa.com/t/senocular-3d-tut-question/42553/9 "2004-02-10T15:49:04Z")

</div>

i figured that out right after i posted, hehe
