package
{
// ----------------------------------------
// Imports
// ----------------------------------------
import flash.display.MovieClip;
import flash.display.Loader;
import flash.text.TextField;
import flash.utils.setInterval;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import gs.*;
public class Inspector extends MovieClip
{
// ---------------------------------------
// Private Variables
// ----------------------------------------
//Same private variables which will help us in the following private methodes
public var rotateX_mc:MovieClip = new MovieClip();
public var rotateY_mc:MovieClip = new MovieClip();
public var rotateZ_mc:MovieClip = new MovieClip();
public var resetAll_mc:MovieClip = new MovieClip();
public var mc:MovieClip = new MovieClip();
public var menu:Array = [[rotateX_mc, 0xFFAACC, "X Rotation"],
[rotateY_mc, 0xAABBCC, "Y Move"],
[rotateZ_mc, 0xDD7766, "X Move"],
[resetAll_mc, 0xEEAA44, "Stop"]];
// These variables determinate the space between buttons
//Also the height and width of each of them
//And the speed of object rotation
public var rotationSquare:MovieClip = new MovieClip();
public var speed:Number = 0.5;
public var spacing:Number = 60;
public var squareWidth:Number = 60;
public var squareHeight:Number = 20;
public var rotateX:Boolean;
public var rotateY:Boolean;
public var rotateZ:Boolean;
// ----------------------------------------
// CONSTRUCTOR
// ---------------------------------------
// Here, the cod will place each button on yhe X aix at regular intervals
//And will assign the setRotation() method
public function Inspector():void
{
drawMc(mc);
mc.addEventListener(MouseEvent.CLICK, onClick)
for(var i:Number=0; i < menu.length; i++)
{
var rotationValue:TextField = new TextField();
rotationValue.selectable = false;
rotationValue.mouseEnabled = false;
drawingSquare(menu[i][0], menu[i][1]);
menu[i][0].x = (spacing + 20) * i;
rotationValue.text = menu[i][2];
menu[i][0].addChild(rotationValue);
menu[i][0].addEventListener(MouseEvent.CLICK, setRotation);
}
drawingObject();
setInterval(rotateIt , 20);
}
// ----------------------------------------
// Private Methods
// ----------------------------------------
private function drawMc(obj:MovieClip):void
{
with(obj.graphics)
{
beginFill(0x333333,1);
drawRect(380,440,50,20);
endFill();
}
this.addChild(obj)
obj.buttonMode = true;
}
private function onClick(e:MouseEvent):void
{
TweenMax.to(mc, 1, {x:200});
}
private function drawingSquare(obj:MovieClip, color:uint):void
// The drawingSquare() method will alow you to create a rectangular shape each time it's invoked
{
with(obj.graphics)
{
beginFill(color, 1);
moveTo(0,0);
lineTo(squareWidth, 0);
lineTo(squareWidth, squareHeight);
lineTo(0, squareHeight);
endFill();
}
this.addChild(obj);
obj.buttonMode = true;
}
private function drawingObject():void
// The drawingObject() method place the square on the stage
{
var pathPhoto:URLRequest = new URLRequest("http://www.stratulat.com/blog/wp-content/air_appicon-tn.gif");
var loader:Loader = new Loader();
loader.load(pathPhoto);
rotationSquare.addChild(loader);
rotationSquare.x = stage.stageWidth * 0.5;
rotationSquare.y = stage.stageHeight * 0.5;
this.addChild(rotationSquare);
}
private function rotateIt():void
// This part will allow you to mange the animation using the setInterval() method
{
if(rotateX)
{
rotationSquare.rotationX+=speed;
}
if(rotateY)
{
rotationSquare.y-=speed;
}
if(rotateZ)
{
rotationSquare.x-=speed;
}
}
private function setRotation(event:MouseEvent):void
// This last method monitors the status of the three Boolean variables: rotateX, rotateY, rotateZ
{
switch(event.currentTarget)
{
case rotateX_mc:
rotateX = true;
rotateY = false;
rotateZ = false;
break;
case rotateY_mc:
rotateX = false;
rotateY = true;
rotateZ = false;
break;
case rotateZ_mc:
rotateX = false;
rotateY = false;
rotateZ = true;
break;
case resetAll_mc:
rotateX = false;
rotateY = false;
rotateZ = false;
break;
rotationSquare.rotationX = 0;
rotationSquare.rotationY = 0;
}
}
}
}