eilsoe
September 26, 2002, 1:31am
1
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???
system
September 26, 2002, 1:33am
2
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!
:-\
system
September 26, 2002, 8:01am
3
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:
system
September 26, 2002, 8:04am
4
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
system
September 26, 2002, 11:04am
5
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??
system
September 26, 2002, 11:05am
6
tried to copy/paste your code lost, still doesn’t work for me…
system
September 26, 2002, 12:00pm
7
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:
system
September 26, 2002, 12:20pm
8
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…
system
September 26, 2002, 12:21pm
9
I gave u the fla in a PM ilyas… check it there…
system
September 26, 2002, 2:37pm
10
Nice effect! You should really work with functions though…
pom :asian:
system
September 26, 2002, 3:07pm
11
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…
system
September 26, 2002, 3:40pm
12
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:
system
September 26, 2002, 3:47pm
13
Hum, you can improve the function a bit:
function easeTo() {
this._x += (_root._xmouse-this._x)/speed;
this._y += (_root._ymouse-this._y)/speed;
}
system
September 26, 2002, 3:49pm
14
okeey, that doesn’t look too hard…
Whaddya mean “define it in the _root” ?
system
September 26, 2002, 3:54pm
15
oh and btw, have u seen my “Drawing machine v.2” in the random threads?
system
September 26, 2002, 4:14pm
16
Define in the _root=put the code in a frame of the main timeline. And I’ll check that
pom :asian: