I've got this weird thing happening (maybe weird) when I use the 3d stuff in cs4.
Basically, I have a stage that is 1100.wide and 500.tall. I have a custom class called Cube.as that if I import and place in the middle of the stage i.e.;
var cube:Cube = new Cube();
addChild(cube);
cube.x = 550;
cube.y = 250;
All the sides, when clicked, return the value of their labels.
but the weird thing is, if I put that cube off center, say
var cube:Cube = new Cube();
addChild(cube);
cube.x = 450;
cube.y = 250;
The mouse doesn't display as a button except when over the left side of the cube face, nor will it return the name of the side (I know that if over the text field it won't show as a mouse, but the click function should still work)...
I've created the class to plug and play (except for the extra Tweener, gs and Zoffset classes you'll need to run it, I'll add the links for those at the bottom of this question) The scroll bar is also a little finicky as i don't have the patience to set the x offset dynamically for this example.
Cube.as ***
package
{
import com.gskinner.motion.GTween;
import caurina.transitions.Tweener;
import com.leebrimelow.utils.Math2;
import com.theflashblog.fp10.SimpleZSorter;
import fl.motion.easing.Exponential;
import flash.display.*;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.*;
import flash.text.TextField;
public class Cube extends MovieClip
{
private var container:Sprite;
private var anglePer:Number;
private var sides:int = 4;
private var cubeScroll:Sprite = new Sprite;
private var scrollTab:Sprite = new Sprite;
private var mOffset:Number;
private var xOffset:Number;
private var xMin:Number = 0;
private var xMax:Number;
private var calRadius:Number = 100;
public function Cube()
{
init();
createCube();
initScrollBar();
}
private function createCube():void
{
anglePer = (Math.PI*2) / sides;
for(var i:int=0; i<sides; i++)
{
var imc:MovieClip= new MovieClip();
imc.graphics.lineStyle(.5,0x000000);
imc.graphics.beginFill(0x999999,1);
imc.graphics.drawRect(-calRadius,-calRadius,calRadius*2,calRadius*2);
imc.graphics.endFill();
imc.addEventListener(MouseEvent.CLICK, onClick);
imc.buttonMode = true;
var label:TextField = new TextField();
imc.addChild(label);
label.text = "SIDE: " + i.toString();
imc.myLabel = label.text;
imc.angle = (i*anglePer) - Math.PI/2;
imc.x = Math.cos(imc.angle) * calRadius;
imc.z = Math.sin(imc.angle) * calRadius;
imc.rotationY = 360/sides * -i;
container.addChild(imc);
}
var pp:PerspectiveProjection=new PerspectiveProjection();
pp.projectionCenter = new Point(container.x,container.y);
pp.fieldOfView = 55;
container.transform.perspectiveProjection = pp;
Tweener.addTween(container, {alpha:1,time:.2, delay:1,transition:"easeOutQuart"});
}
private function onClick(e:MouseEvent):void
{
var mc:MovieClip = MovieClip(e.currentTarget);
trace(mc.myLabel);
}
private function initScrollBar():void
{
scrollTab.graphics.beginFill(0x000000,1);
scrollTab.graphics.drawRect(0,0,30,10)
scrollTab.graphics.endFill();
scrollTab.buttonMode=true;
var track:Sprite = new Sprite;
track.graphics.lineStyle(1,0x000000)
track.graphics.lineTo(400,0);
addChild(cubeScroll);
cubeScroll.addChild(scrollTab);
cubeScroll.addChild(track);
cubeScroll.x = -cubeScroll.width/2;
cubeScroll.y = container.y + 150;
scrollTab.addEventListener(MouseEvent.MOUSE_DOWN, scrollCube);
mOffset = -cubeScroll.x;
xMax = cubeScroll.width-scrollTab.width;
}
private function scrollCube(e:Event):void
{
stage.addEventListener(MouseEvent.MOUSE_MOVE, scroll);
stage.addEventListener(MouseEvent.MOUSE_UP, stopScrollCube);
xOffset = (mouseX - mOffset) - cubeScroll.x;
}
private function scroll(e:MouseEvent):void
{
scrollTab.x = mouseX - xOffset;
if(scrollTab.x <= xMin)
{
scrollTab.x = xMin;
}
if(scrollTab.x >= xMax)
{
scrollTab.x = xMax;
}
var sp:Number = scrollTab.x / xMax;
var tw:GTween = new GTween(container, .8, {rotationY:270*sp},
{ease:Exponential.easeOut});
e.updateAfterEvent();
}
private function stopScrollCube(e:Event):void
{
stage.removeEventListener(MouseEvent.MOUSE_MOVE, scroll);
stage.removeEventListener(MouseEvent.MOUSE_UP, stopScrollCube);
}
private function init():void
{
container = new MovieClip();
addChild(container);
container.alpha = 0;
this.addEventListener(Event.ENTER_FRAME, loop);
}
private function loop(e:Event):void
{
SimpleZSorter.sortClips(container);
}
}
}
Here is the example with the x set to 450 http://www.hupcapstudios.com/projects/cubeOff.swf
and here is the example with the x set to 550 (center of the stage) http://www.hupcapstudios.com/projects/cubeCenter.swf
here are the links for the classes
http://code.google.com/p/gtweener/downloads/list
http://code.google.com/p/tweener/
http://code.google.com/p/leebrimelow/source/browse/trunk/as3/com/leebrimelow/utils/Math2.as?r=8