Groups | Blog | Home
all groups > flash actionscript > march 2006 >

flash actionscript : Grow and move action script?


David Stiller
3/15/2006 4:09:12 PM
101658TJF,

[quoted text, click to view]

Let's clarify terminology, real quick, because there are at least two
ways to interpret your question. In Flash, there are shapes and there are
symbols. Shapes cannot be manipulated with ActionScript, but they can be
drawn (to the best of your mathematical skills) with the Drawing API.
Symbols -- that is, movie clips and buttons -- *can* be manipulated by
ActionScript. So if the "shapes" you're talking about are, say, movie
clips, we're in a different ballpark.

Your best bet, in any case, is to look up the "MovieClip class" entry of
the ActionScript Language Reference and give it a good look-see. My mantra
on these forums goes something like this: just about everything in
ActionScript is an object (movie clips, text fields, strings, arrays), and
objects are defined by their namesake classes. The MovieClip class entry of
the AS Language Reference lumps everything you could possibly need to know
about movie clips in one convenient place. Characteristics an object has
are called properties (you'll see a Properties heading); things an object
can do are called metheds (again, a heading); and things an object can react
to are called events.

Look up the MovieClip class, and you'll find all sorts of useful
properties, including _x and _y (for adjusting a clip's position) to
_rotation (for rotating it) to _xscale and _yscale (for adjusting its size).

What you're talking about above is animation, and animation is the
illusion of change over time. You'll want to look at the
MovieClip.onEnterFrame event as a means to repeat your property adjustments
over time. The onEnterFrame event occurs every time the SWF enters a frame,
which is the same as saying it occurs at a rate equivalent to your
document's FPS (frames per second) setting.

Here's the most basic test I can think of. Start a new FLA, draw a
circle and convert it to a movie clip symbol, then give it an instance
name -- say, myClip. Now in frame 1 of the main timeline, call that clip by
name and tell it what to do. Type this ...

myClip.onEnterFrame = function() {
this._x++;
}

Now test your SWF.

That circle should move slowly and consistently to the right. Why?
Well, you've assigned a function to the onEnterFrame event of a given clip.
The word "this" refers to the timeline or object you're in, so in this case,
"this" refers to myClip (because "this" is within the function that is
scoped to this clip). So ...

this._x

.... refers to the MovieClip._x property of the clip with the instance name
myClip. The ++ operator simply adds one to whatever the value of something
already is. If myClip happens to be sitting at 50 pixels in from the left
edge, ++ will turn that 50 to a 51, then to a 52, and so on. Default FPS
setting is 12, so this update will occur 12 times a second.

Change the ++ operator something like += 5 ...

myClip.onEnterFrame = function() {
this._x+=5;
}

.... which will update myClip's _x property by 5 each time, instead of 1.
Try a negative number (or try the -= operator with a positive number).

You'll get the hang of it in no time.

Note your available properties, methods, and events. Change whatever
properties you please. Look up each to see what values are expected for
each. Experiment and have fun.


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

101658TJF
3/15/2006 8:53:27 PM
Hi All,

How would I use an action script to make a shape grow to a certain size and
move to the left at a 45 degree off the movie from where it started. All this
done at the same time with it looping this action 4 times before dissappearing
or stopping?

Thanks.


101658TJF
3/18/2006 11:50:48 PM
AddThis Social Bookmark Button