ActionScript 3 Flex中的AS3 Sprites

public class SpriteWrapper extends UIComponent
{
	public function SpriteWrapper(s:Sprite)
	{
		super();
			
		explicitHeight = s.height;
		explicitWidth = s.width;

		addChild(s);
	}
}

ActionScript 3 Papervision3D View3D类

package com
{

	import org.papervision3d.lights.PointLight3D;
	import org.papervision3d.view.BasicView;
	import org.papervision3d.objects.primitives.Sphere;
	import org.papervision3d.materials.shaders.PhongShader;
	import org.papervision3d.materials.shadematerials.PhongMaterial;
	import org.papervision3d.core.proto.MaterialObject3D;

	public class View3D extends BasicView
	{
		private var light:PointLight3D;
		private var phongMaterial:MaterialObject3D;

		public function View3D()
		{
			super();
			createSomeObjectsOnTheScene();
			this.startRendering();
		}

		public function createSomeObjectsOnTheScene():void
		{
			
			phongMaterial = new PhongMaterial(light, 0x6654FF, 0x060433, 150);

			
			light = new PointLight3D();
			light.x = 1000;
			light.y = 5000;
			light.z = -6000;
			scene.addChild(light);
			
			var tSphere:Sphere = new Sphere(phongMaterial, 50, 10, 10);
			scene.addChild(tSphere);
			
		}
	}
}

ActionScript 3 动态绘制对数螺旋

//
//
// centerX-- X origin of the spiral.
// centerY-- Y origin of the spiral.
// radius--- Distance from origin to outer arm.
// sides---- Number of points or sides along the spiral's arm.
// coils---- Number of coils or full rotations. (Positive numbers spin clockwise, negative numbers spin counter-clockwise)
// rotation- Overall rotation of the spiral. ('0'=no rotation, '1'=360 degrees, '180/360'=180 degrees)
//
function logSpiral(centerX, centerY, radius, sides, coils, rotation){
	//
	with(this){// Draw within the clip calling the function.
		//
		// Start at the center.
		moveTo(centerX, centerY);
		//
		// How far to rotate around center for each side.
		var aroundStep = coils/sides;// 0 to 1 based.
		//
		// Convert aroundStep to radians.
		var aroundRadians = aroundStep * 2 * Math.PI;
		//
		// Convert rotation to radians.
		rotation *= 2 * Math.PI;
		//
		// For every side, step around and away from center.
		for(var i=1; i<=sides; i++){
			//
			// How far away from center
			var away = Math.pow(radius, i/sides);
			//
			// How far around the center.
			var around = i * aroundRadians + rotation;
			//
			// Convert 'around' and 'away' to X and Y.
			var x = centerX + Math.cos(around) * away;
			var y = centerY + Math.sin(around) * away;
			//
			// Now that you know it, do it.
			lineTo(x, y);
		}
	}
}
//
//
lineStyle(2, 0x000000);// Black.
//       (centerX, centerY, radius, sides, coils, rotation)
logSpiral(    250,     200,    320,   700,    14,        0);
lineStyle(2, 0xD0D0D0);// Gray.
logSpiral(    250,     200,    320,   700,    14,       .5);
//
//

ActionScript 3 动态绘制螺旋

//
//
// centerX-- X origin of the spiral.
// centerY-- Y origin of the spiral.
// radius--- Distance from origin to outer arm.
// sides---- Number of points or sides along the spiral's arm.
// coils---- Number of coils or full rotations. (Positive numbers spin clockwise, negative numbers spin counter-clockwise)
// rotation- Overall rotation of the spiral. ('0'=no rotation, '1'=360 degrees, '180/360'=180 degrees)
//
function spiral(centerX, centerY, radius, sides, coils, rotation){
	//
	with(this){// Draw within the clip calling the function.
		//
		// Start at the center.
		moveTo(centerX, centerY);
		//
		// How far to step away from center for each side.
		var awayStep = radius/sides;
		//
		// How far to rotate around center for each side.
		var aroundStep = coils/sides;// 0 to 1 based.
		//
		// Convert aroundStep to radians.
		var aroundRadians = aroundStep * 2 * Math.PI;
		//
		// Convert rotation to radians.
		rotation *= 2 * Math.PI;
		//
		// For every side, step around and away from center.
		for(var i=1; i<=sides; i++){
			//
			// How far away from center
			var away = i * awayStep;
			//
			// How far around the center.
			var around = i * aroundRadians + rotation;
			//
			// Convert 'around' and 'away' to X and Y.
			var x = centerX + Math.cos(around) * away;
			var y = centerY + Math.sin(around) * away;
			//
			// Now that you know it, do it.
			lineTo(x, y);
		}
	}
}
//
//
//
// spiral(centerX, centerY, radius, sides, coils, rotation).
//
// Big center spirals.
lineStyle(27, 0x0000FF);// Blue.
spiral(250, 210, 200, 200, 4, 0);
lineStyle(27, 0xFF0000);// Red.
spiral(250, 210, 127, 200, 2.5, .5);
//
// Small corner spirals.
lineStyle(4, 0xFF00FF);//            Magenta.
spiral(50, 50, 50, 200, 6, 0);//       Big.
spiral(125, 50, 25, 200, 2, .5);//     Small.
lineStyle(4, 0x00FFFF);//            Cyan.
spiral(450, 50, 50, 200, -6, .5);//    Big.
spiral(375, 50, 25, 200, -2, 0);//     Small.
lineStyle(4, 0xFFFF00);//            Yellow.
spiral(50, 350, 50, 200, -4, 0);//     Big.
spiral(125, 350, 25, 200, -3, .5);//   Small.
lineStyle(4, 0x00FF00);//            Green.
spiral(450, 350, 50, 200, 4, .5);//    Big.
spiral(375, 350, 25, 200, 3, 0);//     Small.
//
//

ActionScript 3 摆锤摆

//
//
// Initial variables.
var pendX = 250;
var pendY = 250;
var pendRadius = 200;
var pendArc = 135/360;
var pendSpeed = .005;
var pendCount = 0;
//
//
//
// Make a red footbal-shaped clip.
createEmptyMovieClip("Pendu", 10);
with(Pendu){
	beginFill(0xFF0000);
	moveTo(-20, 0);
	curveTo(0, 15, 20, 0);
	curveTo(0, -15, -20, 0);
}
//
// Make a clip in which to draw the stick holding the pendulum.
createEmptyMovieClip("Stick", 5);
//
//
//
// Swing a point on an eased arc with the given properties.
function pendulum (centerX, centerY, radius, aoi, completionRatio){
	//
	// Use magic trig function to turn linear values between 0
	// and 1 to eased values between -1 and +1.
	var easedOneToNegOne = Math.cos(completionRatio*2*Math.PI);
	//
	// Convert "Angle Of Inclination" from a ratio between 0
	// and 1 to radians.
	var aoiRadians = aoi * 2 * Math.PI;
	//
	// Determine eased rotation of the pendulum in radians.
	// Derived from #3 in the above "Conventions" section.
	var currentRotation = easedOneToNegOne * aoiRadians;
	//
	// Get X and Y coordinates of pendulum at eased angle of rotation.
	var x = centerX + Math.sin(currentRotation) * radius;
	var y = centerY + Math.cos(currentRotation) * radius;
	//
	// Return both X and Y coordinates inside a single 'point' object.
	return {x:x, y:y};
}
//
//
//
// Advance the pendulum to its next position.
function swingPendulum (){
	//
	// Increment the clock counter.
	pendCount += pendSpeed;
	pendCount %= 1;
	//
	// Get the pendulum's new coordinates.
	var point = pendulum (pendX, pendY, pendRadius, pendArc, pendCount);
	//
	// Place the pendulum at its new coordinates.
	Pendu._x = point.x;
	Pendu._y = point.y;
	//
	// Draw a line from the center to the pendulum.
	with (Stick){
		clear();
		lineStyle(2, 0);
		moveTo(pendX, pendY);
		lineTo(point.x, point.y);
	}
}
//
// Keep Swinging the pendulum every time we enter a frame.
onEnterFrame = swingPendulum;
//
//
//
//

ActionScript 3 动态绘制圆圈

/
function magicTrigFunctionX (pointRatio){
	return Math.cos(pointRatio*2*Math.PI);
}
function magicTrigFunctionY (pointRatio){
	return Math.sin(pointRatio*2*Math.PI);
}
//
function drawCircle(centerX, centerY, radius, sides){
	//
	// Move the pen to the first point on the circle.
	this.moveTo(centerX + radius,  centerY);
	//
	for(var i=0; i<=sides; i++){
		var pointRatio = i/sides;
		var xSteps = magicTrigFunctionX(pointRatio);
		var ySteps = magicTrigFunctionY(pointRatio);
		var pointX = centerX + xSteps * radius;
		var pointY = centerY + ySteps * radius;
		this.lineTo(pointX, pointY);
	}
}
//
lineStyle(0);
//
drawCircle(250, 250, 200, 100);
//

ActionScript 3 动态复制对象

my copyFunction(value:Object):Object{
var buffer:ByteArray = new ByteArray();
buffer.writeObject(value);
buffer.position = 0;
var result:Object = buffer.readObject();
return result;
}

ActionScript 3 DocumentClass模板

package {

	import flash.display.MovieClip;

	public class MainClass extends MovieClip {

		public function MainClass() {
			// Constructor Function

		}

	}

}

ActionScript 3 Tweener例子

//Simple Tween
Tweener.addTween(myTextField, {_y:200, time:0.7, transition:"linear"});


// Using events to fade out then disappear (anonymous in-line function)
Tweener.addTween(myMovieClip, {alpha:0, time:1, onComplete:function() { this._visible = false; }});


// Using events to fade out then disappear (using the _autoAlpha special property)
Tweener.addTween(myMovieClip, {_autoAlpha:0, time:1});


// Complex Tweening
fGo = function() { trace ("I'll go!"); };
fGoing = function() { trace ("I'm going!"); };
fGone = function() { trace ("I'm gone!"); };
Tweener.addTween(myMovieClip, {alpha:0, time:1, onStart:fGo, onUpdate:fGoing, onComplete:fGone});


// Using other special properties (that are not related to a variable/property)
Tweener.addTween(mySoundObject, {_sound_volume:100, time:1});
Tweener.addTween(myMovieClip, {_frame:10, time:2.5});


// Using tweener 'templates'
var fadeIn:Object = {alpha:100, time:1};
Tweener.addTween(myMovieClip, fadeIn);

ActionScript 3 Papervision3D - lookAt()

// Just tell it what objects to use!
myObjectOrCamera.lookAt(myOtherObject);