PDA

View Full Version : tricky code, won't work!!



eilsoe
September 25th, 2002, 09:31 PM
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???

eilsoe
September 25th, 2002, 09:33 PM
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!

:-\

pom
September 26th, 2002, 04:01 AM
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:

lostinbeta
September 26th, 2002, 04:04 AM
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

eilsoe
September 26th, 2002, 07:04 AM
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??

eilsoe
September 26th, 2002, 07:05 AM
tried to copy/paste your code lost, still doesn't work for me...

pom
September 26th, 2002, 08:00 AM
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:

eilsoe
September 26th, 2002, 08:20 AM
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...

eilsoe
September 26th, 2002, 08:21 AM
I gave u the fla in a PM ilyas.. check it there...

pom
September 26th, 2002, 10:37 AM
Nice effect! You should really work with functions though...

pom :asian:

eilsoe
September 26th, 2002, 11:07 AM
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...

pom
September 26th, 2002, 11:40 AM
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:

pom
September 26th, 2002, 11:47 AM
Hum, you can improve the function a bit:
function easeTo() {
this._x += (_root._xmouse-this._x)/speed;
this._y += (_root._ymouse-this._y)/speed;
}

eilsoe
September 26th, 2002, 11:49 AM
okeey, that doesn't look too hard...

Whaddya mean "define it in the _root" ?

eilsoe
September 26th, 2002, 11:54 AM
oh and btw, have u seen my "Drawing machine v.2" in the random threads? :P

pom
September 26th, 2002, 12:14 PM
Define in the _root=put the code in a frame of the main timeline. And I'll check that :)

pom :asian:

eilsoe
September 26th, 2002, 12:26 PM
ah, of course... :)