| Subcribe via RSS

X,Y,Z Inspector

February 7th, 2009 | 2 Comments | Posted in ActionScript 3.0

I started to read a AS 3.0 book and i found something very interesting, this interesting thing is this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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;
 
	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 menu:Array = [[rotateX_mc, 0xFFAACC, "X Rotation"],
							     [rotateY_mc, 0xAABBCC, "Y Rotation"],
								 [rotateZ_mc, 0xDD7766, "Z Rotation"],
								 [resetAll_mc, 0xEEAA44, "Reset All"]];
 
		// 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:int = 2;
 
		public var spacing:Number = 60;
		public var squareWidth:Number = 70;
		public var squareHeight:Number = 30;
 
		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
 
		{
			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 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);
		}
 
		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.rotationY+=speed;
			}
			if(rotateZ)
			{
				rotationSquare.rotationZ+=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;
 
				rotationSquare.rotationX = 0;
				rotationSquare.rotationY = 0;
				rotationSquare.rotationZ = 0;
			}
		}
	}
}

Here is the final result:

I hope you like, see ya next time.
Have Fun!

Tags: , , , , ,
Get Adobe Flash playerPlugin by wpburn.com wordpress themes