Tricky code, won't work!

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???

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!

:-\

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:

It works perfectly fine for me.

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

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

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??

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

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

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:

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…

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

Nice effect! You should really work with functions though…

pom :asian:

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…

Take for instance Lost’s easing code:

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:

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:

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:

Hum, you can improve the function a bit:

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

okeey, that doesn’t look too hard…

Whaddya mean “define it in the _root” ?

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

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

pom :asian:

ah, of course… :slight_smile: