# Tricky code, won't work!

**URL:** https://forum.kirupa.com/t/tricky-code-wont-work/5926
**Category:** Uncategorized
**Created:** [September 26, 2002, 1:31am UTC](https://forum.kirupa.com/t/tricky-code-wont-work/5926 "2002-09-26T01:31:38Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![eilsoe](https://avatars.discourse-cdn.com/v4/letter/e/9fc348/32.png) [@eilsoe](https://forum.kirupa.com/u/eilsoe)
#### Post date: [September 26, 2002, 1:31am UTC](https://forum.kirupa.com/t/tricky-code-wont-work/5926/1 "2002-09-26T01:31:38Z")

</div>

I use this code on a ball:\*\*

on(press){  
startdrag(this);  
drag=true;  
}  
on(release){  
stopdrag();  
drag=false;  
}

onClipEvent(enterFrame){  
if(!drag){  
newx=\_root.leader.\_x;  
newy=\_root.leader.\_y-\_root.dist;  
\_x+=(newx-\_x)/10;  
\_y+=(newy-\_y)/10;  
}  
}\*\*

And this works fine, but see here:\*\*

onClipEvent(enterFrame){  
if(!drag){  
if(!\_root.ease){  
newx=\_root.leader.\_x;  
newy=\_root.leader.\_y-\_root.dist;  
\_x+=(newx-\_x)/10;  
\_y+=(newy-\_y)/10;  
}else if(\_root.ease){  
newx=\_root.leader.\_x;  
newy=\_root.leader.\_y-\_root.dist;  
\_x+=(newx-\_x)/10;  
\_y+=(newy-\_y)/10;  
}  
}  
}\*\*

When i add this in the enterframe, nothing happens… the ball is frozen solid! It doesn’t react to the code!!

Why???

---

<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: [September 26, 2002, 1:33am UTC](https://forum.kirupa.com/t/tricky-code-wont-work/5926/2 "2002-09-26T01:33:09Z")

</div>

And i DO set the “ease” to true or false before this code is compiled…!

And i know my code for [!ease] and [ease] are the same, I’m altering it when i get this ball to behave properly!!

I mean, it’s simple code! It should work!

:-\

---

<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: [September 26, 2002, 8:01am UTC](https://forum.kirupa.com/t/tricky-code-wont-work/5926/3 "2002-09-26T08:01:19Z")

</div>

Can you use the code tag, Eilsoe? It’s much more readable that way. And I might be wrong, but I’m under the impression that your code does the same thing whatever the value of ease, no?

pom :asian:

---

<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: [September 26, 2002, 8:04am UTC](https://forum.kirupa.com/t/tricky-code-wont-work/5926/4 "2002-09-26T08:04:54Z")

</div>

It works perfectly fine for me.

Try it. Create a new movie clip. And apply these actions…

```auto
on (press) {
	startDrag(this);
	drag = true;
}
on (release, releaseOutside) {
	stopDrag();
	drag = false;
}
onClipEvent (enterFrame) {
	if (!drag) {
		if (!_root.ease) {
			newx = _root.leader._x;
			newy = _root.leader._y-_root.dist;
			_x += (newx-_x)/10;
			_y += (newy-_y)/10;
		} else if (_root.ease) {
			newx = _root.leader._x;
			newy = _root.leader._y-_root.dist;
			_x += (newx-_x)/10;
			_y += (newy-_y)/10;
		}
	}
}

```

It works great for me

---

<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: [September 26, 2002, 11:04am UTC](https://forum.kirupa.com/t/tricky-code-wont-work/5926/5 "2002-09-26T11:04:00Z")

</div>

well heres the funny part, actually before the code, i assign the object to have a random xy location on load right?

And regarding the enterframe thing, if i go back to just having if(!drag){ , and throw away the ease part, “like in the first code i showed u”, it works again. BUT, even if i then try and use a swapdepths, it does the same thing again!!

It keeps loading itself!! Since i have random xy on LOAD only, i find it weird it disregards the (enterframe) and keeps loading itself…!!

Why aren’t i allowed to do this??

---

<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: [September 26, 2002, 11:05am UTC](https://forum.kirupa.com/t/tricky-code-wont-work/5926/6 "2002-09-26T11:05:32Z")

</div>

tried to copy/paste your code lost, still doesn’t work for me…

---

<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: [September 26, 2002, 12:00pm UTC](https://forum.kirupa.com/t/tricky-code-wont-work/5926/7 "2002-09-26T12:00:26Z")

</div>

That piece of code still doesn’t make sense to me, guys…

```auto
if (!_root.ease) {
	newx = _root.leader._x;
	newy = _root.leader._y-_root.dist;
	_x += (newx-_x)/10;
	_y += (newy-_y)/10;
} else if (_root.ease) {
	newx = _root.leader._x;
	newy = _root.leader._y-_root.dist;
	_x += (newx-_x)/10;
	_y += (newy-_y)/10;
}

```

What’s the difference between the 2? And also what is leader??

pom  
:asian:

---

<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: [September 26, 2002, 12:20pm UTC](https://forum.kirupa.com/t/tricky-code-wont-work/5926/8 "2002-09-26T12:20:51Z")

</div>

As stated ABOVE… the 2 are still identical… i will change one when this works… right now, i have to make it move first…

leader is an object in the main timeline…

---

<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: [September 26, 2002, 12:21pm UTC](https://forum.kirupa.com/t/tricky-code-wont-work/5926/9 "2002-09-26T12:21:38Z")

</div>

I gave u the fla in a PM ilyas… check it there…

---

<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: [September 26, 2002, 2:37pm UTC](https://forum.kirupa.com/t/tricky-code-wont-work/5926/10 "2002-09-26T14:37:40Z")

</div>

Nice effect! You should really work with functions though…

pom :asian:

---

<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: [September 26, 2002, 3:07pm UTC](https://forum.kirupa.com/t/tricky-code-wont-work/5926/11 "2002-09-26T15:07:57Z")

</div>

I thought so… but i figured out what went wrong in my movie…

Is there a descent, ease to understand tut on what functions are and how they work, somewhere?  
I’ve seen functions a thousand places, I just dunno exactly how to “structure” them…

---

<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: [September 26, 2002, 3:40pm UTC](https://forum.kirupa.com/t/tricky-code-wont-work/5926/12 "2002-09-26T15:40:28Z")

</div>

Take for instance Lost’s easing code:

```auto
onClipEvent (load) {
	_x = 0;
	_y = 0;
	speed = 5;
}
onClipEvent (enterFrame) {
	endX = _root._xmouse;
	endY = _root._ymouse;
	_x += (endX-_x)/speed;
	_y += (endY-_y)/speed;
}

```

Instead of doing that for all the time, you could define in the \_root:

```auto
function easeTo() {
	this.endX = _root._xmouse;
	this.endY = _root._ymouse;
	this._x += (this.endX-this._x)/speed;
	this._y += (this.endY-this._y)/speed;
}

```

I added this in front of variables and properties for scope issues (see the AS tricks). Then in your clip:

```auto
onClipEvent (load) {
	_x = 0;
	_y = 0;
	speed = 5;
}
onClipEvent (enterFrame) {
	easeTo();
}

```

It’s actutally even easier with MX… But you see, there’s nothing special, you just rewrite the code inside the body of the function, basically.

pom :asian:

---

<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: [September 26, 2002, 3:47pm UTC](https://forum.kirupa.com/t/tricky-code-wont-work/5926/13 "2002-09-26T15:47:19Z")

</div>

Hum, you can improve the function a bit:

```auto
function easeTo() {
	this._x += (_root._xmouse-this._x)/speed;
	this._y += (_root._ymouse-this._y)/speed;
}

```

---

<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: [September 26, 2002, 3:49pm UTC](https://forum.kirupa.com/t/tricky-code-wont-work/5926/14 "2002-09-26T15:49:26Z")

</div>

okeey, that doesn’t look too hard…

Whaddya mean “define it in the \_root” ?

---

<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: [September 26, 2002, 3:54pm UTC](https://forum.kirupa.com/t/tricky-code-wont-work/5926/15 "2002-09-26T15:54:33Z")

</div>

oh and btw, have u seen my “Drawing machine v.2” in the random threads? 😛

---

<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: [September 26, 2002, 4:14pm UTC](https://forum.kirupa.com/t/tricky-code-wont-work/5926/16 "2002-09-26T16:14:05Z")

</div>

Define in the \_root=put the code in a frame of the main timeline. And I’ll check that 🙂

pom :asian:

---

<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: [September 26, 2002, 4:26pm UTC](https://forum.kirupa.com/t/tricky-code-wont-work/5926/17 "2002-09-26T16:26:00Z")

</div>

ah, of course… 🙂
