PDA

View Full Version : Rotate and ease AS problem



enforcer73
November 24th, 2005, 05:47 PM
Hi all,

Just wondering if I could source some help with a project i'm working on.

What i have is a 3 pronged propeller that looks like this: propeller. (http://img474.imageshack.us/my.php?image=flashpropeller1yu.png)
The propeller is a MC with the instance name of 'propeller'. Inside the propeller MC are 3 MC's which represent the 3 prongs: 'leadership', 'inovation' and 'risktaking' are their instance names.

What i would like to happen is when you click on anyone on the 3 propeller prong buttons, 'leadership', 'inovation' and 'risktaking', the whole propeller rotates smoothly 120 degrees clockwise and eases to a stop.

I know how to do this with tweens and lots of frames and gotoAndPlays, but that is a bit time consuming and messy. I want to use AS as I believe it will be "cleaner" and easier to change/manipulate.

I have searched the forums and found posts which sort of touch on what I want, but don't really help for what I specifically want.

I know how to make the propeller jump 120 degrees in rotation, but what I want is for it to animate and ease to a stop.

Any help would be greatly appreciated.

Cheers,

Enforcer73

enforcer73
November 24th, 2005, 08:29 PM
hey guys, managed to figure out most of the above myself! feel quite stoked about that. Just starting to delve into serious actionscripting, so it's all still very foreign, but i'm learning slowly!

I've got the propeller turning and stopping at 100 degrees. I am also able to change the speed.

All I need to know now is how to ease into with AS?

Anyone know or can help?

Ta,

Enforcer73

NiñoScript
November 24th, 2005, 09:45 PM
dont bother trying to understand it, dont even ask me why i have 3 vars called rotation (_rotation, rotation & rotation_), just use it.. it works :P



MovieClip.prototype._rotateFNC = function(degrees) {
this.rotation = this._rotation+degrees;
this.rotation_ = this._rotation;
this.onEnterFrame = function() {
this.rotation_ += (this.rotation-this.rotation_)*.1;
this._rotation = this.rotation_;
if (this.rotation == Math.ceil(this.rotation_)) {
this._rotation = this.rotation;
delete this.onEnterFrame;
this._rotateBTN(degrees);
}
};
};
MovieClip.prototype._rotateBTN = function(degrees) {
this.onRelease = function() {
this._rotateFNC(degrees);
delete this.onRelease;
};
};
propeller._rotateBTN(120);

enforcer73
November 24th, 2005, 10:17 PM
wow that's pretty rad man and exactly what i wanted! however, after watching my propeller mimick yours, i realised two things:

1. i would like the 3 prongs to be buttons inside the propeller. that is to say that when you click each prong/button, they make the whole propeller rotate, rather than the whole propeller being clickable.

2. and because each prong will be a button, i would like to for example to able to click on say 'prong 2', and it rotates to 'prong 2', rather than just rotating 1 by 1.

Hey, if you could modify your script to do that, well i'd be for ever grateful. I really don't like asking for too much help, but this has really got me fried.

Thanks dude,

Enforcer73

enforcer73
November 24th, 2005, 10:35 PM
hey there,

figured out how to do issue number 1. I just split the script up between the first frame with the propeller in it and the first frame within the propeller.

So frame one within the propeller became:
MovieClip.prototype._rotateBTN = function(degrees) {
_root.controller.propeller.leadership.onRelease = function() {
_root.controller.propeller._rotateFNC(degrees);
delete this.onRelease;
};
_root.controller.propeller.risktaking.onRelease = function() {
_root.controller.propeller._rotateFNC(degrees);
delete this.onRelease;
};
_root.controller.propeller.innovation.onRelease = function() {
_root.controller.propeller._rotateFNC(degrees);
delete this.onRelease;
};
};
_root.controller.propeller._rotateBTN(120);

where leadership, risktaking and innovation are the instance names of the 3 buttons.

Still haven't figured out issue 2 so if you come up with anything...

Enforcer73

NiñoScript
November 25th, 2005, 10:08 PM
i used an idea i had in mind for a while... something i took from zigo's tweening prototypes but i never found the way... suddendly i saw the solution... i remembered that macromedia put an in-flash help :P

i used this function: typeof(expression:Object):String

soo, if u put a number like this: 180
it will rotate 180 degrees (final_rotation = this._rotation+180)

but if u put a string like this: "180"
it will rotate until it gets to 180 degrees (final_rotation = 180)

I've got 2 problems, when i solve them, ill be happy for ever (or at least a week :ponder: )

FIRST: with my dynamic text.... it only shows up when its rotation is equal to 0, i know there is a way, but i cant remember (ill ask my bro tomorrow)
SECOND: i have to deactivate the 3 buttons' onRelease (i think i will use a For-In there)

i also had some problems couse now i have 3 buttons that move 1 mc.. but it was solved quickly ;)



the way to use this prototype is:

MC._rotateBTN(degrees, object:MovieClip);
where MC is the movieclip that will act as a button, degrees can be a number or string as explained before, and object is the movieclip that will rotate

easy huh?

now i have to rest a bit, its 12pm... i'll try to finish it tomorrow, Bye! :sleep: :asleep:

codemonkeypete
November 26th, 2005, 02:22 AM
just read right through the thread. nice solution. For future reference, though, u might try using the mx.transitions prototype, or similar(i use MCTween)... just stating this, because u would then have more fluid movement and control.
MCTween allows for(off the top of my head) - rotateTo, easing(28 animation types) and delays... would be about 3 lines of code in total too ;)

NiñoScript
November 26th, 2005, 06:27 AM
its funnier if u do it by urself ;)

enforcer73
November 27th, 2005, 03:28 PM
Hey NinoScript!

Thanks man, that's friggin awesome! Just what I wanted. You mention it was easy, but I have no idea how some of that is done! I work in Flash but am not up to that advanced AS yet. Hopefully sometime soon.
I wouldn't have tried for something this complex if the client hadn't specfically wanted this propeller to work in this way.

Just a couple of things:

I know you're trying to work on the dynamic text showing while the propeller spins. That's call and all if you wanna do it, but I don't actually need any help on that one, as my text is part of the propeller. (Propeller is a bitmap). But thanks anyway.

Secondly, when the leadership button/blade is in the top most postion, when you click it, it spins 360 degrees and then settles in the desired position. Is there anyway to stop it rotating the 360 degrees first?

Anyway thanks again and if you have any further thoughts, that would be cool!

Enforcer73

NiñoScript
November 28th, 2005, 12:27 AM
about the text thing, i already solved it, i just had to embed fonts :P

and with your "problem":
u could change the parameter to 0 instead of 360, but it would spin to the left...
but the main problem with it, is that flash works with degrees from -180 to 180.. i hate that :(

NiñoScript
November 28th, 2005, 06:32 PM
i should be studing for my last exam... but im too lazy for that :shifty:


here's the fla, im always pleased to help :pleased:

enforcer73
November 29th, 2005, 05:10 PM
cheers Ninoscript,

you have been a big help and without your support, i would be in a pickle with this propeller. It's not 100% how i would like it to work, but it is close enough, and i would feel terrible to ask for any more of your time.

anyway, thanks again, and i'll see you round,

Enforcer73

NiñoScript
November 30th, 2005, 07:43 AM
:thankyou:, but dont worry, just ask.. like i said: im always pleased to help :pleased:

ohh, and i made today my last exam so im on vacations! i got lots of free time (till march)