Hi ,
i have 3d rotating button carousel… go to this URL to see the flash carousel
http://mmu.in/imagebanner/… in this carousel the movieclips are being attached from the library… its called planet1MC, planet2MC, planet3MC…
what i need to do here is set a Timer for this carousel.
1).the animation need to do clockwise in every 15 seconds intervel
2).and also it shouldn’t affect the onRelease function which is already there on the carousel
this is what all i need please take a look at the code below… any doubts please let me know… i hope its clear enough…
Thanks,
import mx.transitions.Tween;
import mx.transitions.easing.*;
import flash.filters.ColorMatrixFilter;
/* Experiment with these settings for different circular animations */
var radiusX:Number = 250;
var radiusY:Number = 10;
var centerX:Number = Stage.width / 2;
var centerY:Number = 150;
var speedValue:Number = 0.1;
var perspective:Number = 100;
//create holder clip at depth 10 to house the rotating menu
var menu:MovieClip = this.createEmptyMovieClip("menu", 10);
//this keeps track of the currently selected menu item
var selectedID:Number;
//positive direction value means animate clockwise, negative value means anti-clockwise
var direction:Number = 1;
var distToTravel:Number;
//setup an array for Item text labels
var arrItems:Array = new Array("Planet 1", "Planet 2", "Planet 3");
var numOfItems:Number = arrItems.length;
//the distance(angle) between each item along the circumference
var sectorDistance:Number = ((Math.PI*2)/numOfItems);
//Colour Transform Arrays used for toggling coloir of selected item
//set transformed object colours to greyscale
var elementsGrey_array:Array = [0.3, 0.59, 0.11, 0, 0,
0.3, 0.59, 0.11, 0, 0,
0.3, 0.59, 0.11, 0, 0,
0, 0, 0, 1, 0];
//set transformed object colours back to normal
var elementsColor_array:Array = [1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0];
var colorMatrix_filter:ColorMatrixFilter = new ColorMatrixFilter(elementsColor_array);
var colorMatrixGrey_filter:ColorMatrixFilter = new ColorMatrixFilter(elementsGrey_array);
//create menu items: attach from Library via linkageID and populate text label
for(var i=0;i<numOfItems;i++)
{
var mc = menu.attachMovie("planet" + (i+1),"item"+i, menu.getNextHighestDepth());
mc.txt_label.text=arrItems*;
mc.angle = i * sectorDistance;
mc.id = i;
mc.filters = [colorMatrixGrey_filter];
mc.onRelease = released;
}
function released()
{
output.text = this.txt_label.text + " has been selected";
/* loop through each item and "reset" its angle
this is to ensure easier tracking and handling of values
ie. if it's previous resting angle was :
>= 2 * PI (a complete positive circle) or
< 0 (gone back beyond 0 due to anti-clockwise rotation
then recalulate an equivalent angle before proceeding */
for(var i=0;i<numOfItems;i++){
var mc:MovieClip = menu["item"+i];
if(mc.angle >= (Math.PI*2)){
mc.angle=mc.angle-Math.PI*2;
}
if(mc.angle < 0){
mc.angle=Math.PI*2 + mc.angle;
}
}
//record this selected menu item
selectedID = this.id;
//if this items current angle is between PI/2 and 1.5PI (ie is currently on the LEFT hand side of circle)
//then set to travel anti-clockwise (shortest path) and calculate how far it needs to travel to be at PI/2 (middle front)
if (this.angle <= 1.5 * Math.PI && this.angle > Math.PI/2){
direction = -1;
distToTravel = this.angle - Math.PI/2;
} else {
//else travelling clockwise
direction = 1;
if(this.angle >=0 && this.angle <= Math.PI/2){
distToTravel = Math.PI/2 - this.angle;
} else {
distToTravel = Math.PI/2 + (2 * Math.PI - this.angle);
}
}
//loop through all items
for(var i=0;i<numOfItems;i++)
{
var mc:MovieClip = menu["item"+i];
if(i==selectedID){
// set this items filters property to the colour transform matrix
mc.filters = [colorMatrix_filter];
//the selected items destination is set to PI (middle front of screen)
mc.dest = Math.PI/2;
} else {
//calculate this items destination
mc.dest = mc.angle + (direction * distToTravel);
// set this items filters property to the greyscale matrix
mc.filters = [colorMatrixGrey_filter];
}
if(direction==1 && mc.angle > mc.dest){
mc.dest = mc.dest + Math.PI*2;
}
mc.onEnterFrame = animate;
}
}
function animate()
{
//used to track whether we've reached destination
var kill:Boolean = false;
//temporarily calculate where the next onEnterframe would position this item
var newAngle:Number = this.angle + direction * speedValue;
//if we're travelling clockwise
if(direction==1){
if(newAngle >= this.dest){
//we've gone PAST our intended destination so set angle TO destination
this.angle = this.dest;
kill = true;
} else {
//set new angle
this.angle = newAngle;
}
//else we're travelling anti-clockwise
} else {
if(newAngle <= this.dest){
//we've gone PAST our intended destination so set angle TO destination
this.angle = this.dest;
kill = true;
} else {
//set new angle
this.angle = newAngle;
}
}
// set x,y position and scale
this._x = Math.cos(this.angle) * radiusX + centerX;
this._y = Math.sin(this.angle) * radiusY + centerY;
var s = (this._y - perspective) /(centerY+radiusY-perspective);
this._xscale = this._yscale = s*100;
this.swapDepths(Math.round(this._xscale) + 100);
if(kill){ // stop this item from animating
delete this.onEnterFrame;
}
}
//kick off the animation by manually triggering an onRelease of the 1st item in the array
menu.item0.onRelease();