
Originally Posted by
iSerce
Hi, I just can't seem to get my head around this - I am a newbie to flash :s
Let me try to explain it better.
What Blizzard showed is another way to go about it, though I find working on the timeline to be a bit more cumbersome (if you want to change something, it takes too my effort for my liking).
First, let's start off with the finished Actionscript and then I'll walk you through it.
Code:
// Include McTween class
#include "mc_tween2.as"
// OnRollover Function
function Over() {
delete this.onRollOver;
this.colorTo(0xff0000, .25, "linear");
this.ySlideTo(this._y-10, .25, "easeOutQuad", 0, function() { this.onRollOut = Out;} );
}
// onRollOut Function
function Out() {
delete this.onRollOut;
this.colorTo(null, .25, "linear");
this.ySlideTo(this._y+10, .25, "easeOutQuad", 0, function() { this.onRollOver = Over; });
}
// Assign Mouse Events to MCs
Link1.onRollOver = Over;
Link2.onRollOver = Over;
Link3.onRollOver = Over;
First and foremost, please go to the website I mentioned in my previous post and download and install McTween. It's a very robust tweening engine and allow for quick and easy management of your tweens. Doing it on the timeline isn't as clean, smooth, or powerful as doing it via actionscript.
First, we want to set the onRollOver state -- this means set the actions that the assigned movieclips will take when someone rolls over them with a mouse pointer.
So, we have this bit of code:
Code:
function Over() {
delete this.onRollOver;
this.colorTo(0xff0000, .25, "linear");
this.ySlideTo(this._y-10, .25, "easeOutQuad", 0, function() { this.onRollOut = Out;} );
}
Since we will be assigning the same set of actions to muliple movieclips (i.e. to each of your links in a menu bar), I've created a function so we can call this multiple times easily.
Now, to the code:
Using McTween sytanx, I have:
Code:
this.colorTo(0xff0000, .25, "linear");
This is saying, change the color of "this" (referring to which ever movieclip your mouse is over) to 0xff0000 (red) in .25 seconds using a "linear" ease type.
You can see the ease types here: http://hosted.zeh.com.br/mctween/animationtypes.html. Having a linear ease type for a color tween is probably best as it's a uniform transition between one color to the other.
Next, we say:
Code:
this.ySlideTo(this._y-10, .25, "easeOutQuad", 0, function() { this.onRollOut = Out;} );
This is saying, when someone mouses over the link ("this"), decrease the y value by 10 pixels (from it's current position) thereby moving it up on the screen. It's also saying to do it in .25 seconds using an "easeOutQuad" animation type.
Here is where it gets a little tricky. The 0 after the "easeOutQuad" means that there should be no delay (i.e. the actions happens immediately when you mouse over). The final bit of code is saying that once this particluar tween is finished, set the onRollOut event (when the user mouses off the particluar button) to a function called "Out".
We will be writing out in a little while.
At the beginning of the code block, i have a delete call. I'll explain this at the end.
Now, to the onRollOut event state.
Code:
// onRollOut Function
function Out() {
delete this.onRollOut;
this.colorTo(null, .25, "linear");
this.ySlideTo(this._y+10, .25, "easeOutQuad", 0, function() { this.onRollOver = Over; });
}
Again, I've used a function to allow for ease of calling it without cumbersome code. The syntax for the tweens here is the same.
Code:
this.colorTo(null, .25, "linear");
This is telling Flash to remove all tinting ("null") and thereby return to default color in .25 seconds using a linear ease. If you wanted to change it to another color, you could add another color instead of "null".
Code:
this.ySlideTo(this._y+10, .25, "easeOutQuad", 0, function() { this.onRollOver = Over; });
}
This bit of code says, increase the y value of "this" movieclip over .25 seconds using an easeOutQuad animation type, with 0 delay and upon completion of the tween, to se the onRollOver state equal to the function called Over which we wrote earlier.
Lastly, we have this:
Code:
// Assign Mouse Events to MCs
Link1.onRollOver = Over;
Link2.onRollOver = Over;
Link3.onRollOver = Over;
This is bascially specifiying which movieclips the actions should be associated with. As an example I've specified 3 links with instance names of Link1, Link2, and Link3.
Now, to why I'm deleting each action when it starts. Like I explained in my previous post, if you are quick with the mouse, it can create some glitchy behavior. Say you're mousing over something, mouse off, and mouse back on again.
So the actions happen as thus (relating to the y shift).
1. Y value decreases by 10
2. Y value increases by 10
3. Y value decreases by 10
Now, if that happened smoothly it wouldn't be a problem. But since you moused off and then quickly right back on, step 2 never finished. So when flash decreases that value by 10, you'll end up with a link that is not back at it's original location.
So, to fix this, we delete each action at it's start and then set it again when the animation is complete. This way, even if you mouse back on to something that is doing the onRollOut animations, it won't effect the look.
Hope that clears it up for you. It's really not very complicated once you play around with it a little. I think you'll find it easier to accomplish than cumbersome timeline animations.
If you have any questions, post back. I'd be happy to clear them up
Bookmarks