all groups > flash actionscript > august 2006 >
You're in the

flash actionscript

group:

self-pausing rotation



self-pausing rotation microes
8/11/2006 7:51:02 PM
flash actionscript: i.m trying to create a 3d rotation much like the widely used carousel only the
rotation i desire consist of four upright movieclips resting on a slanted plane
which rotate onEnterFrame to or following a tween - then pause for a given
number of seconds at the four movieclips positions equal in distance on the
plane.

anybody please?

function around() {
this._x = Math.cos(this.angle) * radiusX + centerX;
this._y = Math.sin(this.angle) * radiusY + centerY;
var s = this._y /(centerY+radiusY);
this._xscale = this._yscale = s*100;
this.angle += this._parent.speed;
}


var radiusX:Number = 250;
var radiusY:Number = 75;
var centerX:Number = Stage.width / 2;
var centerY:Number = Stage.height / 2;
var speed:Number = 0.02;



Re: self-pausing rotation blemmo
8/12/2006 3:50:02 PM
You could use something like this:

var count:Number = 0;
function around() {
count++;
if (count<180) {
this._x = Math.cos(this.angle)*radiusX+centerX;
this._y = Math.sin(this.angle)*radiusY+centerY;
var s = this._y/(centerY+radiusY);
this._xscale = this._yscale=s*100;
this.angle += this._parent.speed;
}
else if(count == 260){
count = 0;
}
}

It counts upwards every time the function is called. If count is below 180, it
rotates the objects. If it's above 180, there's no rotation until count reaches
260, then count is set to 0 and the rotation starts again. You can adjust the
numbers to your needs, as the length of the pause (180 until 260) depends on
your movie's fps (if you use the onEnterFrame event).

hth,
blemmo
Re: self-pausing rotation kglad
8/12/2006 3:52:14 PM
and to make it appear your movieclips are rotating on a 30 degree slant add the following line after your var s line:



Re: self-pausing rotation microes
8/12/2006 6:05:49 PM
nice.
BIG thanks!
Re: self-pausing rotation blemmo
8/12/2006 6:48:34 PM
Just assign each MC a different 'angle' value and the around function to its
onEnterFrame event, e.g.:

for (var i=0; i<4; i++){
_root["mc"+i].angle = i*90;
_root["mc"+i].onEnterFrame = around;
}

The code assumes that the MCs are called 'mc0', 'mc1' etc. The angle
properties will be 0,90,180 and 270; change this as you need.

cheers,
blemmo
Re: self-pausing rotation kglad
8/12/2006 7:54:02 PM
that angle should be in radians:

Re: self-pausing rotation microes
8/12/2006 8:10:49 PM
thanks for showing how to individualize the movieclips in the rotation rather than using duplicates.
i.ll be back after i test things.
Re: self-pausing rotation kglad
8/12/2006 8:23:48 PM
Re: self-pausing rotation kglad
8/13/2006 12:00:00 AM
i'm not sure when you want to pause this but use clearInterval() to pause it
and setInterval() to restart it:



function around() {
for (var i = 1; i<=10; i++) {
mc = _root["mc"+i];
mc._x = Math.cos(mc.angle)*radiusX+centerX;
mc._y = Math.sin(mc.angle)*radiusY+centerY;
var s = mc._y/(centerY+radiusY);
mc._y -= (mc._x-(centerX-radiusX))/Math.sqrt(3);

mc._xscale = mc._yscale=s*100;
mc.angle += mc._parent.speed;
}
updateAfterEvent();
}
var radiusX:Number = 250;
var radiusY:Number = 75;
var centerX:Number = Stage.width/2;
var centerY:Number = Stage.height/2;
var speed:Number = 0.02;
for (var i = 1; i<=4; i++) {
rclip = _root.attachMovie("mc", "mc"+i, i); // if your movieclips are
already on-stage you don't need this line
rclip.angle = (i-1)*Math.PI/2;

}
aroundI = setInterval(around, 10);
Re: self-pausing rotation microes
8/13/2006 12:52:18 AM
i.m rather new at writing actionscript.
could you please provide a working example?
Re: self-pausing rotation microes
8/13/2006 1:27:10 AM
i.m almost there.
Re: self-pausing rotation microes
8/13/2006 5:14:37 PM
THANK YOU for your patience.
i started dabbling in actionscript about a month ago.
i.m a designer who now has a liking for actionscript - amazing!
i just began my reads on OOP , could you suggest of any other good starting
points?


Re: self-pausing rotation kglad
8/13/2006 5:24:16 PM
you're welcome.

someone started a thread yesterday asking about books and actionscript so you
might check that thread.

i don't find it easy to learn without doing. so, i don't use any books and if
i did i would use them as reference materials. because the internet is such a
good reference source, i use it.
Re: self-pausing rotation microes
8/13/2006 5:32:57 PM
i see that!
ok. however i would like to use four different looking movieclips in the rotation, rather than the same mc incremented.
Re: self-pausing rotation kglad
8/13/2006 5:36:54 PM
then use 4 different ones. the code won't change unelss you change the names
of the movieclips.

if you do use different names that are not easy to iterate in a for-loop, you
can sotre those names in an array and use the for-loop to iterate through the
array.
Re: self-pausing rotation microes
8/13/2006 9:17:21 PM
i.m now playing with the degrees and trying to make each clip stop at the same point - the lower left corner of the rotation ?
AddThis Social Bookmark Button