all groups > flash (macromedia) > december 2005 >
You're in the

flash (macromedia)

group:

A few questions about rotation and motion tween


Re: A few questions about rotation and motion tween David Stiller
12/31/2005 12:02:21 PM
flash (macromedia):
Norberto,

[quoted text, click to view]

CW (clockwise) and CCW (counter-clockwise) are great for full 360
rotations, but as you've discovered, they don't work for partial rotations.
Your best bet is to set a keyframe at yor start angle, set another keyframe
at your end angle (rotated by hand), and motion tween the frames between
them.

[quoted text, click to view]

I would use CW or CCW between my first and second keyframes, then the
above suggestion between my second and third keyframes.

[quoted text, click to view]

The on() handler is mainly for buttons. Although certain button events
will register with movie clips, enterFrame is not one of them, since
enterFrame is only for movie clips. Movie clips require the onClipEvent()
handler.

onClipEvent(enterFrame) {
trace(this._rotation);
}

The above indeed outputs a movie clip's rotation, even during tweening.

[quoted text, click to view]

In Flash, the closest analogue to Director's dotted motion path is the
motion guide. (This is one of dozens of points where Director is better, in
my opinion -- and, of course, there are dozens of points where Flash is
better.)

[quoted text, click to view]

The angle *reported* by a movie clip is not necessarily the angle to
which it adheres. You can, indeed, set a movie clip to 350. It will rotate
to 350 degrees, but will report its rotation as -10.

[quoted text, click to view]

We'll probably need to hear a bit more about your requirements, and
you'll almost certainly have to work more of this out via ActionScriipt. In
this way, your angle can be maintained behind the scenes with relatively
high precision, while in the foreground, your movie clip displays the figure
visually.

I encourage you to use the newer approach to assigning event handlers.
on() and onClipEvent() are somewhat dated, having been introduced in Flash
5. Since Flash MX (Flash 6), one can assign event handlers in the following
manner:

clipInstanceName.onEnterFrame = function() {
// anonymous function statements here
}

or

function namedFunction() {
// statements here
}
clipInstanceName.onEnterFrame = namedFunction;

.... which benefits the developer in two ways: A) the ActionScript can be
organized into a single layer (generally named "scripts" or "actions"), and
B) handlers assigned in this manner can be created and destroyed at runtime
(clipInstanceName.onEnterFrame = null).

In the above approach, the ActionScript is typed into a frame rather
than directly to a movie clip or button, and of course an instance name is
required so that the ActionScript knows which object to target. Instance
names may be assigned via the Propeties inspector or, in some cases, via
ActionScript.

See the "MovieClip class" entry of the ActionScript Language Reference
to see all the available methods, properties, and events for all movie
clips. This is arguably your most important class to learn, since the
published SWF itself is a movie clip.


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

A few questions about rotation and motion tween Norbertofh
12/31/2005 1:38:04 PM
Hello,

I'm new to Flash and I'm having some hard trouble rotating an object, so I
would like to pose a few questions.

Question 1:
What I want to do is to rotate an arbitrary angle without ActionScript, so
the CW and CCW Rotate are not an option. This leaves me with the "Auto" option,
but even in this case it doesn't work well.
When using "Auto" rotation Flash seems to choose the shortest way, so if the
angle is greater than 180 it rotates CCW to the 360-angle position. Another
particular example is the rotation of more than one complete turn: take the
example of one and a half turn (540 degrees), how do I rotate this amount, as
the Auto rotation only rotates the "half turn"?

Question 2:
I created a simple rotation using the CW rotate mode, so that the object
rotates one time (360 degrees). After that I created a simple action that
outputs the _rotation property on every entered frame (on(enterframe)...). I
thought I was going to get the current angle of the object, but instead I get a
constant value.
It seems that the constant value is sort of the "angle per frame" applied to
the object, but I need to know the exact angle of the object. Is there a way to
do this?

Question 3:
Is there a way to see the motion path of an object? I'm not talking about
motion guides, but the path created between tweened keyframes (in Director the
motion path is displayed as points - one for each in-between frame)?

Best regards,
Norberto
Re: A few questions about rotation and motion tween David Stiller
12/31/2005 2:31:32 PM
Norberto,

[quoted text, click to view]

I cannot answer this definitively, but in my experience, it's true. I
should clarify that you can indeed *set* a movie clip's _rotation property
to whatever number you like. The rotation will become modulo 360 of that
number (that is, 365 becomes 5).

[quoted text, click to view]

I believe that's right.

[quoted text, click to view]

Since Flash MX 2004 (aka Flash 7), ActionScript allows class-based OOP
via external .as files, which may be categorized just as easily in folders
outside the FLA entirely. It's a different paradigm from Director's (just
as Director's is different from -- and, I'll agree, superior to -- the older
way this was approached in Flash. I don't know your experience with other
languages, so "class-based OOP" may or may not be meaningful to you.
Flash's class files are probably most comparable to Directors' parent
scripts.

Classes define a datatype (an object), so, for example, the MovieClip
class describes everything possible with a movie clip symbol. Same goes for
the TextField class, the Array class, and so on. These classes define the
unique combination of methods (things the object can do), properties
(gettable/settable characteristics the object has), and events (things the
object can react to) that make an object the type it is.

With ActionScript 2.0, you may define your own classes, as illustrated
in the excellent three-part AS 2 Primer at Joey Lott's website:

http://www.person13.com/articles/

.... otherwise, you must use JavaScript-like techniques for prototype-based
OOP, as illustrated in this imcomplete (but very good) site here:

http://www.debreuil.com/docs/ch01_Intro.htm

In this second approach, scripts need not be saved as separate .as files
(required in the class-based approach), but can be stored in external files
and included via the #include directive.

This all assumes you want to program in an object-oriented manner, of
course. I find ActionScript wonderfully suited for it, and in this way you
may keep most (98% or so) of your code in external files, separate from your
Library assets. This organization is the approach I use most often,
especially when a project is complex.

[quoted text, click to view]

I remember those days! I rarely use Director nowadays -- just a matter
of circumstance, not necessarily preference -- but Flash is certainly as
powerful nowadays ... just powerful in different ways and via different
routes. Flash has a Behaviors panel. It's not the same as Director's,
since ActionScript Behaviors are not stored in the Library.

[quoted text, click to view]

This is the number one reason to put your scripts into frames. :) In
many cases, you can put all your scripts into a single frame (frame 1), so
give that a whirl.


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

Re: A few questions about rotation and motion tween Norbertofh
12/31/2005 3:48:02 PM
Ok, a fourth question about rotation: does the angle or a rotation varies
between -180 and 180? I ask this because I tried the following ActionScript
code:

onClipEvent (enterFrame) {
this._rotation = this._rotation + 10;
trace("_rotation: " + this._rotation);
}

and the trace result was (I've cutted some intermediate results):
_rotation: 10
_rotation: 20
_rotation: 30
[...]
_rotation: 170
_rotation: 180
_rotation: -170
_rotation: -160
[...]
_rotation: -20
_rotation: -10
_rotation: 0

So it does not go through 0-360 degrees. Instead of going to 190 degrees after
180, it goes to -170.

For calculation purposes I need to have the rotation in a wide angle range
(even more than 360 degrees). How can I achieve that?
Re: A few questions about rotation and motion tween Norbertofh
12/31/2005 5:43:58 PM
David, thank you very much for your thorough answer.

About the on() event... I got confused, because in fact I meant the
onClipEvent method.
So the MovieClip object only stores its angle on the screen, not the actual
rotated angle, right? I suppose I could solve this with an internal value that
keeps the actual rotation, but this would only be possible if I affect directly
the _rotation property (and know which angle is passed), otherwise if I use,
for instance, the Tween class I can't determine which angle is the current
angle at a given time.

Thank you very much for your suggestions about development in Flash. In deed
I'm trying to figure out a way to organize better the code in a Flash project.
I must say that Director also wins a few points in this matter, as scripts are
kept as library members, just like any other graphic, sound, video, etc, and
the behaviors (as scripts assigned to objects on stage are called) are very
"object centered" - one can assign as many behaviors as needed and see them in
a stack on a specific panel. In Flash it is very hard to keep up with the
scripts, as they're not refered on the library and one needs to go through
every keyframe of each object, or even through each object to see all the
different actions on the flash project.
Re: A few questions about rotation and motion tween NSurveyor
12/31/2005 7:08:12 PM
Keep a variable to track how much you rotated. For example:

rotated = 0;
my_mc.onEnterFrame = function(){
this._rotation+=10;
rotated+=10;
if(rotated>=540){
delete this.onEnterFrame;
}
}

Here's what I posted on a thread you asked about using Motion Tweens:

Suppose you want 900 degrees. Well that's 360*2+180. So, on the final
keyframe, set the rotation to 180 (you can use the Modify > Transform > Scale
and Rotate for precision). Then, in the motion tween use CW and set 2 for times.

So, basicaly DEGREES_TO_TURN = 360*TIMES+FINAL_FRAME_DEGREES for CW. And for
CCW, I believe you would use;

DEGREES_TO_TURN = 360*TIMES+(360-FINAL_FRAME_DEGREES);

So, an example this. You want to rotate 450 degrees CCW. 450 = 360*1+90. So,
TIMES would be and the final degrees for the clip would be 360-90 or 270.
Re: A few questions about rotation and motion tween Norbertofh
12/31/2005 8:06:44 PM
NSurveyor, thank you very much for the help. I thought of your suggestion
before, but the problem is that it would only work if I was affecting the
_rotation directly, as in your code. If, for instance, the rotation was being
affected by means of the Tween class, I couldn't track the rotation.
One thing that I still didn't understand is why the _rotation property is a
constant value when the rotation is done by tweening on the timeline.

David, I also have to thank you again.
I actually have a background on OOP programming, so I'm starting to explore
the Flash capabilities in this matter. As I have some experience with JAVA, I'm
finding it to be very similar to the Flash approach. With a bit of research I'm
sure I'll manage to organize things as good (or even better) as Director allows.

In the end I'm just a bit disapointed with the animation editing features of
Flash. I've been seeing so many espectacular Flash animations and I thought
that Flash provided enhanced keyframing tools. Nevertheless now I realise that
the animation through the timeline is somehow limited.
Now that Macromedia belongs to Adobe, maybe they'll merge the keyframing
features of Adobe After Effects with Flash. This is by far one of the best
tools I've ever used in terms of animation capabilities, as it is very easy to
edit each individual keyframe and fine-tuning the overall animation.
Re: A few questions about rotation and motion tween David Stiller
1/1/2006 2:10:32 PM
Norberto,

[quoted text, click to view]

Check out the Tween class yourself to see how it's put together. If
you're on Windows, check out your equivalent of this folder ...

C:\Program Files\Macromedia\Flash 8\en\First Run\Classes\mx

.... and you'll find the Tween class in the transitions folder. They're all
simply text files (.as files), so if you want to extend or alter Tween
somehow to return values rather than set properties of an object, have at
it! :)

[quoted text, click to view]

It isn't for me. When I used the onClipEvent() handler -- rather than
on() -- my movie clip correctly reported its rotation, though the number was
always between -180 and 180.

[quoted text, click to view]

Agreed. ActionScript is increasingly more ECMA-based, and ActionScript
3 -- still a year off, or so -- looks every more like Java. Check out
http://labs.macromedia.com/ for an early alpha release. To my thinking,
this is the biggest overhaul to ActionScript since Flash 4 to Flash 5.
(Flash Player 8.5+, in fact, has a completely new virtual machine. For the
time being, this player hosts two virtual machines: one for AS1/AS2 and the
other for AS3.)

[quoted text, click to view]

What inspire me are the results people get given the state of these
tools as they are. Check out the animation tutorials of Chris Georgenes,
here ...

http://www.macromedia.com/devnet/flash/3d_animation.html

.... Chris makes his bread and butter with Flash animation and has developed
a number of useful workflows over the years.

[quoted text, click to view]

Sure, but try to export an After Effects animation to a lightweight,
vector-based web animation. ;) I agree with you, AE is excellent for what
it does. Adobe Flash -- or 3rd party Flash-compatible animation tools, such
as Toon Boom Studio -- are excellent for what they do. If Adobe can combine
the best characteristics of each, they'll have a killer app. (As if they
didn't already, right!) :) It can only get better. I'm looking forward to
whatever comes.


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

Re: A few questions about rotation and motion tween David Stiller
1/1/2006 8:17:31 PM
Norberto,

[quoted text, click to view]

Good, old fashioned timeline tweening. Here are my steps.

1) Draw a square on the Stage.
2) Select, then Modify > Convert to Symbol > MovieClip.
3) Select movie clip, open Actions panel, then type ...

onClipEvent(enterFrame) {
trace(this._rotation);
}

4) Add keyframe to frame 20.
5) Select a frame between 1 and 20, right click, Create Motion Tween.
6) Test SWF.
7) Sample output:

18.8185882568359
37.8577575683594
56.9045104980469
75.9357757568359
94.5601196289062
113.576522827148
132.619277954102
151.664413452148
170.688873291016
-170.688873291016
-151.664413452148
-132.619277954102
-113.576522827148
-94.5601196289062
-75.9357757568359
-56.9045104980469
-37.8577575683594
-18.8185882568359


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

Re: A few questions about rotation and motion tween Norbertofh
1/2/2006 12:43:59 AM
Originally posted by: Newsgroup User

[quoted text, click to view]

It isn't for me. When I used the onClipEvent() handler -- rather than
on() -- my movie clip correctly reported its rotation, though the number was
always between -180 and 180.



Can you tell me if you created an animation using the Tween class or by
tweening keyframes? When I create the animation (a simple rotation) purely with
keyframes and tweening (on the score window) the _rotation property is a
constant value, that for what I understood is the degrees per frame (or maybe
not).

AddThis Social Bookmark Button