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;
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
and to make it appear your movieclips are rotating on a 30 degree slant add the following line after your var s line:
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
that angle should be in radians:
thanks for showing how to individualize the movieclips in the rotation rather than using duplicates. i.ll be back after i test things.
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);
i.m rather new at writing actionscript. could you please provide a working example?
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?
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.
i see that! ok. however i would like to use four different looking movieclips in the rotation, rather than the same mc incremented.
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.
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 ?
Don't see what you're looking for? Try a search.
|