Gwah! AS2 3D Carousels mindf*ck!
This advance AS2 junk is hard... :S
I've finally managed to get a working Carousel perfectly centred and all. (Only toke 2 days.)
Now I've been tryin' to figure out how to get it so on the release for the icons it'll gotoAndPlay the correct scene. Basically what I'm doing is trying to make a 3D interactive Carousel menu for my bios page for my site. (Plus it'll be a nice lil' thing I can always modify and use later, actually was thinkin' of makin' a preloader one which speeds up the more it loads. :P)
Anyway here's the code...
import mx.utils.Delegate;
var numOfItems:Number;
var radiusX:Number = 200;
var radiusY:Number = 50;
var centerX:Number = Stage.width/2.2;
var centerY:Number = Stage.height/2;
var speed:Number = 0.05;
var perspective:Number = 130;
var home:MovieClip = this;
var tooltip:MovieClip = this.attachMovie("tooltip", "tooltip", 10000);
tooltip._alpha = 0;
var xml:XML = new XML();
xml.ignoreWhite = true;
xml.onLoad = function() {
var nodes = this.firstChild.childNodes;
numOfItems = nodes.length;
for (var i = 0; i<numOfItems; i++) {
var t = home.attachMovie("item", "item"+i, i+1);
t.angle = i*((Math.PI*2)/numOfItems);
t.onEnterFrame = mover;
t.toolText = nodes[i].attributes.tooltip;
t.icon.inner.loadMovie(nodes[i].attributes.image);
t.ref.inner.loadMovie(nodes[i].attributes.image);
t.icon.onRollOver = over;
t.icon.onRollOut = out;
t.icon.onRelease = released;
}
};
function over() {
home.tooltip.tipText.text = this._parent.toolText;
home.tooltip._x = this._parent._x;
home.tooltip._y = this._parent._y-this._parent._height/2;
home.tooltip.onEnterFrame = Delegate.create(this, moveTip);
home.tooltip._alpha = 100;
}
function out() {
delete home.tooltip.onEnterFrame;
home.tooltip._alpha = 0;
}
and now for part I'm trying to figure out... Also: This was the first time I've ever imported a XML into flash so bear with me here.
'Kay now what I've been trying to do lately is find a parent object where I can get the tooltip var from within the XML file. 'Cause inside of it each image has a tooltip var. ex:
<icon image="derek.png" tooltip="Derek" />
So by using the tooltip vars for each image from within the XML file I can identify each object thus telling it to gotoAndPlay the correct scene/frames aka the actual bio.
The code I've been screwing around with is as followed...
function released() {
trace(this._parent.toolText);
if (tipText="Derek") {
gotoAndPlay("derekb");
} else {
trace(this._parent.toolText);
if (tipText="Darryl") {
gotoAndPlay("darrylb");
}
}
}
Now I realize as it is it is wrong, that's 'cause I'm still tryin' to figure this junk out. I'm just tryin' to make it able to go to two diffirent bios right now. derekb and darrylb. I put "b"s at the end so that it doesnt get confused.
Anyway for now I'm trying to think up a way to make a new var to be able to identfy the different icons easier. So when I click Derek icon it goes to the Derek bio and vice versa with the rest.
Now for the rest of the code!
function moveTip() {
home.tooltip._x = this._parent._x;
home.tooltip._y = this._parent._y-this._parent._height/2;
}
xml.load("icons.xml");
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*100;
this.angle += this._parent.speed;
this.swapDepths(Math.round(this._xscale)+100);
}
this.onMouseMove = function() {
speed = (this._xmouse-centerX)/2500;
};
Sure I could use basic buttons or somethin`for the bio menu, but this is a lot funner.. I don`t know why but I love challageing myself to the point my mind blows up. :P