ActionScript 3 全屏使用ActionScript 3

<!-- HTML -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
	<head>
		<title></title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<script type="text/javascript" src="swfobject.js"></script>
		<script type="text/javascript">
			var flashvars = {};
			var params = {};
			params.allowfullscreen = "true";
			var attributes = {};
			swfobject.embedSWF("untitled.swf", "myAlternativeContent", "800", "600", "9.0.0", false, flashvars, params, attributes);
		</script>
	</head>
	<body>
		<div id="myAlternativeContent">
			<a href="http://www.adobe.com/go/getflashplayer">
				<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
			</a>
		</div>
	</body>
</html>

//AC3:
import flash.display.StageDisplayState;

function goFullScreen():void{
    if (stage.displayState == StageDisplayState.NORMAL){
        stage.displayState=StageDisplayState.FULL_SCREEN;
    }
    else {
        stage.displayState=StageDisplayState.NORMAL;
    }
}

stage.addEventListener(MouseEvent.CLICK, _handleClick)

function _handleClick(event:MouseEvent):void{
    goFullScreen();
}

ActionScript 3 在褪色alpha时将MC的组成部分展平以停止“显示”

mc.blendMode = BlendMode.LAYER;

ActionScript 3 AS3:Facebook身份验证类

package com.chrisaiv
{
	import com.facebook.events.FacebookEvent;
	import com.facebook.utils.FacebookSessionUtil;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	
	import mx.controls.Alert;

	public class FBAuthenticate extends EventDispatcher
	{
		private var session:FacebookSessionUtil;

		private var _currentMethod:Function;
		
		public function FBAuthenticate( fbSession:FacebookSessionUtil, func:Function )
		{			
			_currentMethod = func;
			
			session = fbSession;
			session.addEventListener( FacebookEvent.WAITING_FOR_LOGIN, fbWaitingForLoginHandler, false, 0, true );
			session.addEventListener( FacebookEvent.CONNECT, fbOnConnectHandler, false, 0, true );
			session.login();
		}

		/**************************************
		 * Facebook Connect/Login Event Handlers
		**************************************/
		private function fbOnConnectHandler( e:FacebookEvent ):void
		{
			//Continue where the user last left off before requiring Authentication
			dispatchEvent( new Event( Event.COMPLETE ) );
		}
		
		private function fbWaitingForLoginHandler( e:FacebookEvent ):void
		{
			showAlert( "Click OK after you've logged in", "Logging In" );
		}			
		
		private function fbValidateLogin( e:Event ):void
		{
			session.validateLogin();
		}
		
		/**************************************
		 * Alert
		**************************************/
		private function showAlert( message:String, header:String ):void
		{
			//The user has returned from the log-in page and are now clicking "OK"
			var alert:Alert = Alert.show( message, header );
				alert.addEventListener( Event.CLOSE, fbValidateLogin, false, 0, true );				
				alert.addEventListener( Event.CLOSE, alertCloseHandler, false, 0, true );				
		}
		
		private function alertCloseHandler( e:Event ):void
		{
			
		}
		
		/**************************************
		 * Getters / Setters
		**************************************/
		public function get currentMethod():Function
		{
			return _currentMethod;
		}		
		
	}
}


/**************************
* This belongs outside of the class
**************************/

private function isAuthenticated():Boolean
{
	if( fbSession == null || !fbSession.facebook.is_connected ){
		return false;
	}
	return true;
}

private function fbGoAuthenticate( method:Function ):void
{
	fbAuthenticate = new FBAuthenticate( fbSession, method );					
	fbAuthenticate.addEventListener( Event.COMPLETE, fbAuthenticateComplete, false, 0, true );				
}

private function fbAuthenticateComplete( e:Event ):void
{
	updateStatus( "You are logged into Facebook" );

	var currentMethod:Function = FBAuthenticate(e.currentTarget).currentMethod;
	//Continue where the User Last Left Off
	currentMethod();
}
private function getPhotoAlbums():void
{	
	//-- AUTHENTICATE USER: Force USER to Login() Before calling FB API
	if( !isAuthenticated() ){ fbGoAuthenticate( arguments.callee ); return; } 
	
	var call:FacebookCall = fbook.post( new GetAlbums( fbook.uid ) );
		call.addEventListener( FacebookEvent.COMPLETE, photoAlbumsCompleteHandler, false, 0, true );					
}

private function photoAlbumsCompleteHandler( e:FacebookEvent ):void
{
	var albumsResponseData:GetAlbumsData = e.data as GetAlbumsData;
}

ActionScript 3 AS3:我最喜欢的Singleton的例子

package
{
	public class Singleton
	{
		private static var _instance:Singleton;
		private static var _okToCreate:Boolean = false;
		
		public function Singleton()
		{
			if( !_okToCreate ){
				throw new Error("Error: " + this + 
					" is not a singleton and must be " + 
					"accessed with the getInstance() method");				
			}
		}
		
		public static function getInstance():Singleton
		{
			if( !Singleton._instance ){
				_okToCreate = true;
				_instance = new Singleton();
				_okToCreate = false;
			}
			return _instance;
		}
	}
}

ActionScript 3 检查AS3中的连接

import air.net.URLMonitor;
import flash.net.URLRequest;
import flash.events.StatusEvent;

var monitor:URLMonitor = new URLMonitor(new URLRequest(‘http://www.enginyoyen.com’));
monitor.addEventListener(StatusEvent.STATUS, checkHTTP);
monitor.start();

function checkHTTP(e:StatusEvent) {
if (monitor.available) {
test_txt.text ="Internet is available";
} else {
test_txt.text ="No internet connection available";
}
}

ActionScript 3 AS3:删除阵列中的重复项

function removeDuplicate(arr:Array) : void{
    var i:int;
    var j: int;
    for (i = 0; i < arr.length - 1; i++){
        for (j = i + 1; j < arr.length; j++){
            if (arr[i] === arr[j]){
                arr.splice(j, 1);
            }
        }
    }
}

var arr:Array = new Array("a", "b", "a", "c", "d", "b");
removeDuplicate(arr);

ActionScript 3 AS3静音所有声音

import flash.media.SoundMixer;

SoundMixer.soundTransform = new SoundTransform(0);

ActionScript 3 AS3:基本多点触控示例

package
{
	import flash.display.Sprite;
	import flash.events.TouchEvent;
	import flash.text.AntiAliasType;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.ui.Multitouch;
	import flash.ui.MultitouchInputMode;

	[SWF(width=320, height=460, frameRate=24, backgroundColor=0xEB7F00)]
	public class MultitouchExample extends Sprite
	{
		private var dots:Object;
		private var labels:Object;
		private var labelFormat:TextFormat;
		private var dotCount:uint;
		private var dotsLeft:TextField;
		private static const LABEL_SPACING:uint = 15;
		
		public function MultitouchExample()
		{
			super();

			this.labelFormat = new TextFormat();
			labelFormat.color = 0xACF0F2;
			labelFormat.font = "Helvetica";
			labelFormat.size = 11;
			
			this.dotCount = 0;

			this.dotsLeft = new TextField();
			this.dotsLeft.width = 300;
			this.dotsLeft.defaultTextFormat = this.labelFormat;
			this.dotsLeft.x = 3;
			this.dotsLeft.y = 0;
			this.stage.addChild(this.dotsLeft);
			this.updateDotsLeft();

			this.dots = new Object();
			this.labels = new Object();

			Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
			this.stage.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
			this.stage.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
			this.stage.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);
		}

		private function onTouchBegin(e:TouchEvent):void
		{
			if (this.dotCount == Multitouch.maxTouchPoints) return;
			var dot:Sprite = this.getCircle();
			dot.x = e.stageX;
			dot.y = e.stageY;
			this.stage.addChild(dot);
			dot.startTouchDrag(e.touchPointID, true);
			this.dots[e.touchPointID] = dot;
			
			++this.dotCount;

			var label:TextField = this.getLabel(e.stageX + ", " + e.stageY);
			label.x = 3;
			label.y = this.dotCount * LABEL_SPACING;
			this.stage.addChild(label);
			this.labels[e.touchPointID] = label;

			this.updateDotsLeft();
		}
		
		private function onTouchMove(e:TouchEvent):void
		{
			var label:TextField = this.labels[e.touchPointID];
			label.text = (e.stageX + ", " + e.stageY);
		}
		
		private function onTouchEnd(e:TouchEvent):void
		{
			var dot:Sprite = this.dots[e.touchPointID];
			var label:TextField = this.labels[e.touchPointID];
			
			this.stage.removeChild(dot);
			this.stage.removeChild(label);
			
			delete this.dots[e.touchPointID];
			delete this.labels[e.touchPointID];
			
			--this.dotCount;

			this.updateDotsLeft();
		}
		
		private function getCircle(circumference:uint = 40):Sprite
		{
			var circle:Sprite = new Sprite();
			circle.graphics.beginFill(0x1695A3);
			circle.graphics.drawCircle(0, 0, circumference);
			return circle;
		}

		private function getLabel(initialText:String):TextField
		{
			var label:TextField = new TextField();
			label.defaultTextFormat = this.labelFormat;
			label.selectable = false;
			label.antiAliasType = AntiAliasType.ADVANCED;
			label.text = initialText;
			return label;
		}
		
		private function updateDotsLeft():void
		{
			this.dotsLeft.text = "Touches Remaining: " + (Multitouch.maxTouchPoints - this.dotCount);
		}
	}
}

ActionScript 3 网络摄像头与AS3

package  {
	
	import flash.media.Camera;
	import flash.media.Video;
	
	
	public class CameraDemo extends Video {
		
		private var camera:Camera;
		private var camQuality:int = 80;
		private var fps:int = 30;
		
		public function CameraDemo(w:Number = 640, h:Number = 480) {
			/*	Set the width and height of the camera's display  */
			this.width = w;
			this.height = h;
			startCamera();
		}
		
		public function startCamera():void 
		{
			/*	Get the default camera for the system	*/
			camera = Camera.getCamera();
			/* Set the bandwidth and camera image quality	*/
			camera.setQuality(0, camQuality);
			/*	Set the size of the camera and frames per second   */
			camera.setMode(this.width, this.height, fps);
			/*	Attach the camera to the video object.. In this case the current class.  */
			this.attachCamera(camera);
		}
	}
}

ActionScript 3 AS3 3D图库 - 屏幕到屏幕效果

import com.greensock.*;
import com.greensock.easing.*;
var lastRotX = 0;
var lastRotY = 0;

for(var i=0; i<gal.numChildren; i++){
	var self = gal.getChildAt(i);
	self.addEventListener(MouseEvent.CLICK,windowClicked);
}

addEventListener(Event.ENTER_FRAME,loop);
function windowClicked(e){
	var self = e.currentTarget;
	removeEventListener(Event.ENTER_FRAME,loop);
	var timeline = new TimelineLite();
	var transition = new TimelineLite();
	timeline.insert(TweenLite.to(gal,1,{x:(self.x)*-1,y:(self.y)*-1, z:-1210, ease: Sine.easeInOut}));
	timeline.insert(transition);
	lastRotX = gal.rotationX;
	lastRotY = gal.rotationY;
	var oppRotX = gal.rotationX*-1;
	var oppRotY = gal.rotationY*-1;
	transition.append(TweenLite.to(gal,0.5,{rotationX:oppRotX*7,rotationY:oppRotY*7, ease: Sine.easeOut})); 
	transition.append(TweenLite.to(gal,0.5,{rotationX:0,rotationY:0, ease: Sine.easeIn})); 	
	self.removeEventListener(MouseEvent.CLICK,windowClicked);
	self.addEventListener(MouseEvent.CLICK,zoomOut);
}
function zoomOut(e){
	var self = e.currentTarget;

	self.addEventListener(MouseEvent.CLICK,windowClicked);
	var timeline = new TimelineLite();
	var transition = new TimelineLite({onComplete:function(){	addEventListener(Event.ENTER_FRAME,loop) }});
	timeline.insert(TweenLite.to(gal,1,{x:573,y:422, z:0, ease: Sine.easeOut}));
	timeline.insert(transition);
	transition.append(TweenLite.to(gal,0.5,{rotationX:lastRotX*7,rotationY:lastRotY*7, ease: Sine.easeOut})); 
	transition.append(TweenLite.to(gal,0.5,{rotationX:0,rotationY:0, ease:Sine.easeInOut})); 

}
function loop(e){
	var distx:Number = mouseX / 650;
	var disty:Number = mouseY / 450;
	TweenLite.to(gal, 2, {
						rotationY:(-70 + (140*distx))*0.06,
						rotationX:(70 - (140*disty))*0.06,
						ease:Expo.easeOut
				 });
}