FORUMS: list search recent posts

carousel button snippet

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Crystal Shannon
carousel button snippet
on Apr 20, 2009 at 12:59:11 am

I posted prior and didn't receive a response. I am going to repost because I have changed quiet a bit of information so I wanted to start fresh and condense everything as not to be overwhelming.

Please help, I've tried the gotoandlearn forum without success

I've followed the carousel 1 tutorial on
I've altered the code to my needs:
I have a previous and next button that I have added.
I have the images loaded via an array and have centered the first image
on stage at 6:00 vs the original 3:00 by adding +.9 to the following code:

t.angle = (i*((Math.PI*2))/numOfItems)+(Math.PI+.9);

Finally, I have added the following to the next button (right_btn) to go to the next image in the array:

right_btn.onPress = function() {
for (var i = 0; i<numOfItems; i++) {
var t:MovieClip = home["item"+i];

Now, what I'm looking to do is ease the next one into place. Right now, it just jumps into place.

The next thing I want to do is have each one ease into the center one by one. As it stands, when the carousel turns, the images shift off center.

The rest of my code is the same from the tutorial download files. If requested, I will post but wanted to keep it short and sweet.

Any help would be appreciated, I'm stuck at this point.

Return to posts index

Crystal Shannon
Re: carousel button snippet
on Apr 20, 2009 at 10:26:41 am

Nevermind, I figured it out.
Thanks anyhow.

Not to be a stick in the mud, but I've posted in the Flash forum before and I never get a reply. I wonder what I'm doing wrong. Maybe it's not monitored like the html section of creative cow is.

Anyhow, I'll still post over there though :)

Return to posts index

Chris Morgan
Re: carousel button snippet
on Oct 27, 2009 at 8:30:59 pm

I seem to be having the same issue. I wonder if you'd be willing to share your solution? I used a different value (just trial and error) to move it to the 6 o'clock position but am having trouble keeping it on center.

Return to posts index

Crystal Shannon
Re: carousel button snippet
on Oct 27, 2009 at 8:43:03 pm

from what I can remember, I changed the same code above to another calculation.

Here it is if you wanna go through it. I got it to work, but if you click the right/left button like 40-50 times.. it doesn't exactly start landing in the center.. it will drift off center. BUT it works for what I needed it to do.. since there were only 4 icons in my carousel.. there would be no reason for someone to hit the button that many times.

import mx.utils.Delegate;
import mx.transitions.Tween;
import mx.transitions.easing.*;
import flash.filters.BlurFilter;
var blur:BlurFilter = new BlurFilter(0, 0, 1);//remove to remove Blur
var stand:BlurFilter = new BlurFilter(0,0,0);//remove to remove Blur

var icons:Array = new Array();

var numOfItems:Number = 5;
var radiusX:Number = 250;
var radiusY:Number = 40;
var centerX:Number = Stage.width/2;
var centerY:Number = Stage.height/1.6;
var speed:Number = 0;//keep at 0 to keep the carousel stationary
var perspective:Number = 380;
var home:MovieClip = this;
var ssOn:Number = 0;
var targetSpeed:Number = 0;
var easeSpeed:Number = 1.2;

this.filters = [stand];//remove to remove Blur

function mover() {

this._x = Math.cos(this.angle)*radiusX+centerX;
this._y = Math.sin(this.angle)*radiusY+centerY;
var s:Number = (this._y+perspective)/(centerY+radiusY+perspective);
this._xscale = this._yscale=s*90;
this.angle += this._parent.speed;
this._alpha = (Math.round(this._xscale)+10);
//remove following 3 lines to remove Blur
blur.blurX = Math.round(Math.sin(this.angle - Math.PI) * 10);
blur.blurY = Math.round(Math.sin(this.angle - Math.PI) * 10);
this.filters = [blur];


var t:MovieClip = home[item+i];
for (var i = 0; i<numOfItems; i++) {
var t = this.attachMovie(icons[i], "item"+i, i+2);
t.angle = (i*((Math.PI*2))/numOfItems)+(Math.PI*0.49);//added *.0.49 so the carousel started in the 6 o'clock postion.

t.onEnterFrame = mover;

new Tween(home, "_alpha", Regular.easeIn, .0, 100, 1, true);

function resetSS() {
delete home.onEnterFrame;
home.onEnterFrame = function () :Void {
var distance:Number = targetSpeed - speed;
var newDistance:Number = distance / easeSpeed;
speed = targetSpeed - newDistance;
if (Math.round(speed * 100) == 0) {
speed = 0;

var myInt:Number;
right_btn.onPress = function() {
//speed = .215;
speed = .213;
left_btn.onPress = function() {
//speed = -.215;
speed = -.213;



Return to posts index

Crystal Shannon
Re: carousel button snippet
on Oct 27, 2009 at 8:48:59 pm

come to think of it, I think I used a completely different code.
It's been awhile, but you may be able to use it to your advantage. It's AS3.. anyhow, good luck.

Return to posts index

Chris Morgan
Re: carousel button snippet
on Oct 28, 2009 at 1:07:02 pm

Thanks! This is great, I appreciate you taking the time to respond. It's similar to what I have but your math seems much more accurate.

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 All Rights Reserved