ActionScript 3 电子邮件验证

function isValidEmail(email:String):Boolean
{
    var emailExpression:RegExp = /([a-z0-9._-]+?)@([a-z0-9.-]+)\.([a-z]{2,4})/i;
    return emailExpression.test(email);
}

ActionScript 3 在网格布局中定位显示对象

for (var i:uint = 0; i < 20; i++)
{
    var displayObject:MyDisplayObject = new MyDisplayObject();
    displayObject.x = displayObject.width * ( i % 5 );
    displayObject.y = displayObject.height * Math.floor( i / 5 );
    addChild(displayObject);
}

ActionScript 3 AS3:从Flash保存JPEG

import com.adobe.images.JPGEncoder;

function createJPG(mc:MovieClip, n:Number, fileName:String) {
	
	var jpgSource:BitmapData = new BitmapData (mc.width, mc.height);
		jpgSource.draw(mc);
	var jpgEncoder:JPGEncoder = new JPGEncoder(n);
	var jpgStream:ByteArray = jpgEncoder.encode(jpgSource);

	var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");

	//Make sure to use the correct path to jpg_encoder_download.php
	var jpgURLRequest:URLRequest = new URLRequest ("download.php?name=" + fileName + ".jpg");
		jpgURLRequest.requestHeaders.push(header);
		jpgURLRequest.method = URLRequestMethod.POST;
		jpgURLRequest.data = jpgStream;

	var loader:URLLoader = new URLLoader();
	navigateToURL(jpgURLRequest, "_blank");
}


//createJPG(movieClip, quality, fileName);
createJPG(myMovieClip, 90, "myDog");

///////////////////////////////////////////////////////////////
//This is an Example of the Server-side that will return the JPEG
///////////////////////////////////////////////////////////////
/*
<?php
if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {
	// get bytearray
	$im = $GLOBALS["HTTP_RAW_POST_DATA"];
	
	// add headers for download dialog-box
	header('Content-Type: image/jpeg');
	header("Content-Disposition: attachment; filename=".$_GET['name']);
	echo $im;
}  else echo 'An error occured.';
?>
*/

ActionScript 3 随机化一个数组

for (var i:uint = 0; i < myArray.length; i++)
{
   var rand:uint = int(Math.random() * myArray.length);
   myArray.push( myArray.splice( rand, 1 )[0] );
}