PDA

View Full Version : Need help adapting/advancing my AS



yorkshirepuddin
November 21st, 2002, 03:20 AM
After solving my previous problem, I had to go and make it a little harder on myself :crazy:, but I guess you learn through experimentation right?

Anyway, it's a little beyond my knowledge of AS and would appreciate some help.

Okay, here's my situtation.

I have 3 MC's that are functioning as buttons. All 3 MC's have the following AS attached to them:

onClipEvent (enterFrame) {
mousey = _root._Ymouse;
if (mousey<_y) {
followmouse = _y-mousey;
} else {
followmouse = mousey-_y;
}
moveSpeedy = followmouse/10;
if (mousey<_y) {
_y = _y-movespeedy;
} else {
_y = _y+movespeedy;
}
}
onClipEvent (enterFrame) {
if (this._y<8) {
this._y = 8;
}
if (this._y>232) {
this._y = 232;
}
}
{

Ignore the settings for the min and max Y postion, I need to refigure those out.

Anyway, each clip is positioned appoximately 20 pixels apart on the Y.

So, when they follow the mouse, I would like the separation to remain - meaning the never sit at the same x position. Also, if you go to this URL to see it - http://members.rogers.com/limee/test/navigation.html - you'll note that its pretty difficult to perform the rollover function (it works fine without the mouse follow).

I think that's it. I half asleep so I may have more in the morgan.

Hope someone can help.

YP

yorkshirepuddin
November 21st, 2002, 03:27 AM
HOLD THAT THOUGHT! I think I may almost have it and I'd like the challenge instead of bumming knowledge off everyone.

I'll be back (but hopefully not).

YP

lostinbeta
November 21st, 2002, 03:32 AM
Well here are some tips on your journey...

The buttons are offset from your mouse, this means that as the mouse approaches them, there is no way it can catch up, because they move away from the mouse.

YOu could prevent this by A)Making them stop moving at a certain point or B)Not have them move away from the mouse (lol).

yorkshirepuddin
November 21st, 2002, 03:41 AM
Originally posted by lostinbeta

YOu could prevent this by A)Making them stop moving at a certain point or B)Not have them move away from the mouse (lol).


Thanks for the tips. I need 'um. Not going as well as I thought, but lack of sleep may be the culprit.

lostinbeta
November 21st, 2002, 03:44 AM
you can define a maxhigh y position and a maxlow y position and use if statements to stop them at each of the points so they don't go any further from the mouse (or just a maxlow position really)

yorkshirepuddin
November 21st, 2002, 03:48 AM
That sounds great, shame I don't know how to do it. Got myself a challenge for the morning now.

Thanks for your help.

lostinbeta
November 21st, 2002, 03:51 AM
no problem... that last hint was a big one.... I hope you can work with that tomorrow :)

Just remember these key things

if

_y

<

lowmax

_y

=

lowmax


LOL, hope these key things help you :)

yorkshirepuddin
November 21st, 2002, 03:54 AM
It all sounds great what you're saying. Let's see what tomorrow brings. You set me a challenge now, I shall deliver.:P

yorkshirepuddin
November 21st, 2002, 01:25 PM
lost ... you there? i need some clues ... but not direct solutions ... i want to figure this out on my own as much as possible ...

btw .. i found another script and used that ... now of each MC I have the following:

// Detect Y coordinate of mouse and follow
onClipEvent (load) {
speed = 5;
}
onClipEvent (enterFrame) {
endY = _root._ymouse;
_y += (endY-_y)/speed;
if (this._y<-80) {
this._y = -80;
}
if (this._y>143) {
this._y = 143;
}
}


The only this that changes is the speed ... I have it set to 5, 10, and 15 so each MC comes down/up at a different offset ...

Hope you're around.
YP

lostinbeta
November 21st, 2002, 01:46 PM
Why do you have a negative value for the max low?

yorkshirepuddin
November 21st, 2002, 01:52 PM
Originally posted by lostinbeta
Why do you have a negative value for the max low?
sorry, you lost me ... where do i have that?

oh you mean the - 80? well, when i play this thing over, with - 80 it stops at the right point.

lostinbeta
November 21st, 2002, 01:55 PM
Oh ok.

Well if it stops at the right point.... then what is the situation? What isn't working?

yorkshirepuddin
November 21st, 2002, 02:05 PM
Okay, let's go from the top.

I've just reformatted the AS to make more sense and combined on ClipEvents ... here's the code now.

// Detect Y coordinate of mouse and follow
onClipEvent (enterFrame) {
speed = 5;
endY = _root._ymouse;
_y += (endY-_y)/speed;
if (this._y<- 80) {
this._y = - 80;
}
if (this._y>143) {
this._y = 143;
}
}

Okay, so here's what I need to figure out. I still have the same problems as last night, i.e. the boxes never reach the mouse pointer so the user won't be able to activate the button.

Let's sort that first.

Now, you mentioned something about Maxhigh and Max low ... is this what I need to implement next to make the buttons able to reach the pointer.

Btw, truely, thanks for the help here, i'm sure you got better things to do, so I really appreciate it. It helps having someone actually guide you through as opposed to doing a tut.

Plus, I prefer to work it out myself so that I understand it better.
YP

yorkshirepuddin
November 21st, 2002, 02:06 PM
Just to add, the only time the user is able to activate the MC buttons is when they are at the max and min on the Y ...

lostinbeta
November 21st, 2002, 02:08 PM
Ok, because your situation is that your boxes move away from your mouse, by defining contraints to how far the boxes can go will allow you to catch up to them because they will stop at a certain point.

yorkshirepuddin
November 21st, 2002, 02:13 PM
Where have I don't that - told them to move away?

So, I guess what you're saying is, although they are to follow the mouse when it moves, there final destination will be at the same y of the mouse?

yorkshirepuddin
November 21st, 2002, 02:15 PM
I'm guessing I need to change or add to this part:

_y += (endY-_y)/speed;

am i getting close?

yorkshirepuddin
November 21st, 2002, 02:52 PM
I think I've done it. :) I didn't actually have to change any of the AS, I just had to take all the MC's out of an MC and drop them individually on the timeline.

Why would that be though?

lostinbeta
November 21st, 2002, 03:07 PM
Sorry I didn't notice your second script was different from your first. Your first script had the buttons offset from the mouse so you could never touch them (as in the example link you showed).

Not sure what you mean about taking an mc out of an mc and placing it on the maintimeline and it worked.

If it was what I am thinking of, that really makes no sense.

yorkshirepuddin
November 21st, 2002, 03:13 PM
I'm not suprised that I'm confusing you. It's hard to explain stuff when you barely understand it yourself.

I'll try and explain the structure I had and now have.

HAD

Originally, I had my main MC which was called Navigation. Within that MC, I had my three MC's that act as the navigation for the site (i.e. section 1, 2 and 3). On each of those MC's (the 3), I was assigning the AS we've been going over.

NOW HAVE

I have completely omitted the main MC and just dropped the 3 MCs on the main stage timeline and again applied the AS to them.

Understand now?

lostinbeta
November 21st, 2002, 03:19 PM
Ok, yeah it makes sense. Sorry, I was going by the example link and code in the beginning, I didn't take notice the second code was different.

Does it make any difference if you change _y += (endY-_y)/speed; to this._y += (endY-this._y)/speed; I don't see why it would, but sometimes "this" makes all the difference.

It is good that you got it working either way though.

PS: Haven't slept much, and the posts last night were at like 3am...lol.

yorkshirepuddin
November 21st, 2002, 03:26 PM
Here, take a look at the new one. http://members.rogers.com/limee/test/navigation.html

I'm stoked I got it working (with help of course).

Now, you'll see when you go, I have a new problem. :)

I hear you on the sleep thing. I should of given in last night, everything made much more sense this morning after some kip.

yorkshirepuddin
November 21st, 2002, 03:27 PM
Time to figure out how to change the depth of those mcs, so which every is activated is on top. That what i need to do right?

I recall seeing something in my as book ... test time!

lostinbeta
November 21st, 2002, 03:29 PM
Which is a problem, that they are not aligned in the end, or that some of the blue areas are under the other movie clips?

If that is it, you can use swapDepths for that.

http://www.kirupa.com/developer/actionscript/swapdepth.asp

PS: You replied to your reply while I was replying to your reply as well...lol.

yorkshirepuddin
November 21st, 2002, 03:32 PM
i don't mind that they are not aligned (i think - i'm sure i'll change my mind - typical desginer) ... yes i want whatever is rolled over to be on top ... i knew it was the depth thing ... a drink and a quick smoke and on to the next challenge ... this navigation will be the death of me ...

don't even ask what i want to do with it next ... i'm a classic case of jumping in at the deep end huh?

lostinbeta
November 21st, 2002, 03:35 PM
Lol, yeah I was in that boat and I jumped into the deep ocean, but it was fun :P

yorkshirepuddin
November 21st, 2002, 03:39 PM
as long as you surface ... all is good ... :)

lostinbeta
November 21st, 2002, 03:41 PM
I was saved by a dolphin.........

::::don't worry about me, I am in the decompression chamber, it is messing with my head::::

yorkshirepuddin
November 21st, 2002, 03:43 PM
Originally posted by lostinbeta
I was saved by a dolphin.........


nice save ... :) ... i incredibly crazy about them ... i swam with them last year ... okay going off topic ... *L* ...

lostinbeta
November 21st, 2002, 03:44 PM
I went whale watching and saw whales and dolphins....lol.


Off topic again.... let me know your progress, gotta go now :)

yorkshirepuddin
November 21st, 2002, 03:46 PM
I worked with a killer whale once as one of those resorts ... got a kiss any everything ... beat that ... :P :)

I'll catch you later ... I'm sure I'll be asking questions soon ... take care and thanks!

yorkshirepuddin
November 21st, 2002, 04:01 PM
Originally posted by lostinbeta

Does it make any difference if you change _y += (endY-_y)/speed; to this._y += (endY-this._y)/speed; I don't see why it would, but sometimes "this" makes all the difference.


No. I just tried this but it took me back to square one. There must be a way, ideally I would like to have all this nested in a MC for ease of management etc. Any other ideas? Sound I perhaps no use .this ... could that confuse things?

yorkshirepuddin
November 22nd, 2002, 02:11 PM
Hey lost, just wanted to let you know I was able to put all those MCs into a master one.

I posted elsewhere and some guy told me it was because you had to set the master mc to 0, 0 on the stage. Works like charm.

Thank god for boards eh?

lostinbeta
November 22nd, 2002, 03:25 PM
Awesome :)

Neo_Clone01
November 22nd, 2002, 09:31 PM
where else did u post, just curious