Mombu the Programming Forum sponsored links

Go Back   Mombu the Programming Forum > Programming > adjust speed of this animation
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 18th April 15:07
david stiller
External User
 
Posts: 1
Default adjust speed of this animation



smrdo,


When people say I "have" this code, do they mean they found the code?
Did they write it, or was it in a book, or what? I see this a lot, I "have"
this code. (This is a tangent, I know, but the expression is a curious one.
When I create an FLA, I don't say I "have" an FLA, I say I "put together" an
FLA, or I "made" an FLA.)


The variable you need is, in a sense, already in place. The variable
named counter is the one used to determine when the clip is as wide as
another variable, myWidth, and counter is the one used to change the _width
property of the mask movie clip.


The ++ operator increments a number by one. Writing counter++ is the
same as writing ...

counter = counter + 1

.... so that's your ticket to increasing the speed of your counter variable's
change. You could increase it by 2 every time, or by 3, or much higher
(say, by 10) each time to see a quicker change.

I'm guessing this code is within an onClipEvent(enterFrame) handler,
right? If so, then myWidth is presumably defined in the same clip's
onClipEvent(load) handler. (If I'm off base here, you'll have to take the
spirit of what I'm saying, rather than the letter.)

Somewhere before you get to the if() statement above, you'll have to
initialize a variable named, say, speed. Do this in the same way you
initialized myWidth. Rather than using ++, which always increments by 1,
you can use +=, which will increment by whatever you put after it. I would
break the line up into two lines:

counter += 10;
this.MaskMC._width = counter;

.... the above would first increment counter by 10, then apply the new value
to MaskMC's _width property. If the number ten is contained in your new
variable, speed, it might look like this:

counter += speed;
this.MaskMC._width = counter;

But then, if you think about it, why not simply increment the _width
property directly?

this.MaskMC._width += speed;

After all, that does exactly the same thing, without having to "pass the
baton" to the counter variable. Naturally, if you do without the counter
variable, you'll have to change the if() statement a bit. If you're not
incrementing counter, then it's useless to compare counter against myWidth.
But the key thing here is the _width property anyway. So use that for the
comparison ...

if (this.MaskMC._width == myWidth) {
this.gotoAndStop(3);
} else {
this.MaskMC._width += speed;
trace("this is execution " + speed);
}

Do you see how that accomplishes the same goal?

You can call the speed variable counter, if you like (call it whatever).
The point is what if you change its value now, that change will affect the
speed at which the mask mc grows. If you make its value a negative number,
mask mc will shrink! Possibly useful.

Something to keep in mind: back when you were incrementing by 1 each
time, it was guaranteed that counter -- which is to say, actually,
MaskMC._width -- would eventually equal the value of myWidth. But if you
start incrementing by any other number, _width may never equal myWidth. (If
myWidth is 50 and you're incrementing by 3s, your sequence might be 45, 48,
51, 54, etc.) So I would change that == operator to >=, which means
"greater than or equal to."

Make sense?


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


  sponsored links


Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666