ActionScript 保险丝套件导入

import com.mosesSupposes.fuse.*;
ZigoEngine.register(Fuse,PennerEasing);


function bounceSpeakers(){
var f:Fuse = new Fuse();
f.push([{target:right_speaker, _y:94, seconds:0.25, ease:"easeOutBounce"},
		{target:left_speaker, _y:94, seconds:0.25, ease:"easeOutBounce"}]);
f.push([{target:right_speaker, _y:96, seconds:0.25, ease:"easeOutBounce"},
		{target:left_speaker, _y:96,  seconds:0.2, ease:"easeOutBounce"}]);
f.push({func:bounceSpeakers});
f.start();
}

bounceSpeakers();

ActionScript ActionScript getURL使用javascript浏览器大小调整

getURL("javascript:NewWindow=window.open('yourpage.html','newWin','width=1000,height=650,left=0.toolbar=No,location=No,scrollbars=No,status=No,resizable=No,fullscreen=No'); NewWindow.focus();void(0);");

ActionScript InvisibleScroller类

import mx.transitions.OnEnterFrameBeacon;

/**
 * A scroller class with no visible interface
 * Uses masked area to calculate position
 */
class com.orazal.tools.InvisibleScroller {
	// Enter Frame Beacon
	static var __initBeacon = OnEnterFrameBeacon.init();
	// Target Clips
	private var mask:MovieClip;
	private var masked:MovieClip;
	// Properties
	private var dir:String = "vertical";
	private var offset:Object;
	private var oPos:Object;
	private var newPos:Number;
	private var easing:Number = 5;
	
	// Constructor
	public function InvisibleScroller(dire:String, mask_mc:MovieClip, masked_mc:MovieClip) {
		dir = dire;
		mask = mask_mc;
		masked = masked_mc;
		// Store original masked positions
		oPos = {x:masked_mc._x, y:masked_mc._y};
		offset = {x:mask._x - masked._x , y:masked._y - mask._y};
		// Start listening to mouse
		Mouse.addListener(this);
		// EnterFrame listener
		MovieClip.addListener(this);
	}
	
	/**
	 * Allows to change easing
	 */
	public function setEasing(amount):Void{
		easing = amount;
	}
	
	/**
	 * Enter Frame
	 */
	private function onEnterFrame():Void {
		if(dir == "vertical"){
				masked._y  += (newPos - masked._y )/ easing;
		}
		if(dir == "horizontal"){
				masked._x  += (newPos - masked._x )/ easing;
		}
	}
	
	/**
	 * Mouse listener
	 */
	private function onMouseMove() {
		var point:Object = {x:_root._xmouse, y:_root._ymouse};
 		mask.globalToLocal(point); 
		if(this.dir == "vertical"){
			var percent:Number = point.y/mask._height;
			var maskedTotal = offset.y + this.masked._height + 20
			var max:Number = maskedTotal - this.mask._height ;
			if(percent >= 0 && percent<=1){
				newPos =(-max*percent ) + oPos.y ;
			}
		}
		if(this.dir == "horizontal"){
			var percent:Number = point.x/mask._width;
			var maskedTotal = offset.x + this.masked._width + 20;
			var max:Number =  maskedTotal - this.mask._width ;
			if(percent >= 0 && percent<=1){
				newPos =(-max*percent ) + oPos.x;
			}
		}
			
		
	};
	
	public function destroy():Void{
		MovieClip.removeListener(this);
		Mouse.removeListener(this);
		delete this;
	}
}

ActionScript replaceByBitmap

/**
 * Makes a bitmap copy of an image clip and 
 * rewrites it with the same name, depth, position.
 *
 * @param	target 		The movie clip to replace.
 * @param	transparent	Specifies whether the bitmap image supports per-pixel transparency.
 * @param	fillColor	A 32-bit ARGB color value that you use to fill the bitmap image area.
 */
function replaceByBitmap(target:MovieClip, transparent:Boolean, fillColor:Number):Void {
	import flash.display.BitmapData;
	var ox:Number = target._x;
	var oy:Number = target._y;
	if(transparent && fillColor){
		var bm:BitmapData = new BitmapData(target._width, target._height, true, 0x00FFFFFF);
	}else{
		var bm:BitmapData = new BitmapData(target._width, target._height);
	}
	bm.draw(target);
	var copy_mc:MovieClip = target._parent.createEmptyMovieClip(target._name, target.getDepth());
	copy_mc.attachBitmap(bm, 0, "never", true);
	copy_mc._x = ox;
	copy_mc._y = oy;
}

ActionScript PositionUtils

class com.orazal.tools.PositionUtils {
	/**
	 * Returns x and y positions for a grid 
	 *
	 * @param amount		The total amount of items
	 * @param	limit			The row or column limit before line break
	 * @param	width		The item's with
	 * @param	height		The item's height
	 * @param	direction	Horizontal or Vertical
	 * @returns An array with a position object with the x and y properties
	 */
	public static function getGridPositions(amount:Number, limit:Number, 
											width:Number, height:Number, 
											direction:String):Array {
		// Set direction as horizontal if none is found
		if (!direction) {
			direction = "horizontal";
		}
		var pos_ar:Array = new Array();
		for (var i:Number = 0; i<20; i++) {
			switch (direction) {
			case "horizontal" :
				var column:Number = i%limit;
				var row:Number = Math.floor(i/limit);
				break;
			case "vertical" :
				var row:Number = i%limit;
				var column:Number = Math.floor(i/limit);
				break;
			}
			var xPos = column*width;
			var yPos = row*height;
			pos_ar.push({x:xPos, y:yPos});
		}
		return pos_ar;
	}

	/**
	 * Calculates a clip's final size and position from a provided registration point
	 *
	 *@param	clip	The movieclip to zoom
	 *@param	percent	The amount to zoom
	 *@param	xOffset	The percentage (in decimals) to offset horizontally from clip's center
	 *@param	yOffset	The percentage (in decimals) to offset vertically from clip's center
	 *@returns 	An object with the final width, height, x and y positions
	 */
	public static function zoomFromPoint(clip:MovieClip, percent:Number, 
										 xOffset:Number, yOffset:Number):Object {
		// Convert zoom percent to decimals
		percent /= 100;
		// Get original width and height
		var originalW = clip._width/(clip._xscale/100);
		var originalH = clip._height/(clip._yscale/100);
		// Center register position if not provided
		if (!xOffset) {
			var xOffset:Number = 0.5;
		}
		if (!yOffset) {
			var yOffset:Number = 0.5;
		}
		// Determine x and y positions               
		var centerX = clip._x+(clip._width*xOffset);
		var centerY = clip._y+(clip._height*yOffset);
		// Determine final positions 
		var final:Object = new Object();
		final.width = originalW*percent;
		final.height = originalH*percent;
		final.x = centerX-(final.width*xOffset);
		final.y = centerY-(final.height*yOffset);
		return final;
	}
}

ActionScript constrainToArea

/*
* Checks a  clip's position and size and repositions inside an area
*
*@param		clip		Movieclip to reposition
*@param		area		An object indication the area that the clip should be constrained to
*@param		reposition	Boolean indicating if movieclip's position should be modified
*@param		hSpacing	Horizontal margin from the border
*@param		vSpacing	Vertical margin from the border
*@returns	An object with the x and y values that are inside the area
*/
function constrainToArea(clip:MovieClip, area:Object, reposition:Boolean, hSpacing:Number, vSpacing:Number):Array {
	if (!hSpacing) {
		var hSpacing:Number = 0;
	}
	if (!vSpacing) {
		var vSpacing:Number = 0;
	}
	var clipPoint:Object = new Object();
	clipPoint.x = clip._x;
	clipPoint.y = clip._y;
	clip._parent.localToGlobal(clipPoint);
	// Return same position
	var newX = clip._x;
	var newY = clip._y;
	// Reposition on x
	var overX = area.width-(clipPoint.x+clip._width);
	if (overX<0) {
		newX -= Math.abs(overX)+hSpacing;
	}
	if (clipPoint.x<0) {
		newX += Math.abs(clipPoint.x)+hSpacing;
	}
	// Reposition on y   
	var overY = area.height-(clipPoint.y+clip._height);
	if (overY<0) {
		newY -= Math.abs(overY)+vSpacing;
	}
	if (clipPoint.y<0) {
		newY += Math.abs(clipPoint.y)+vSpacing;
	}
	if (reposition) {
		clip._x = newX;
		clip._y = newY;
	}
	return {x:newX, y:newY};
}

ActionScript 服务器端ActionScript Notes

/*
Between the time an instance is created and destroyed, a number of things can happen. To simplify how things work, they are divided into three sections: startup, midlife, and shutdown.

Each application object is a singleton object. Each instance gets it's own application object which is an instance of the Application class.

These are all the standard event handler method of the application object
*/

/***************************
Startup
***************************/
application.onAppStart = function (  ) {
	//A. onAppStart is where to Initialize counters, variables, id's, etc
	trace( "onAppStart> " + application.name + " is starting at " + new Date() );
	
	//B. You can set up a Server-side shared object to synchronize clients 
	this.so = SharedObject.get(application.name + ".com", true);
	
	//C. This is the proper way to set default variables. It allows for expansion
	if(this.so.getProperty("t" == undefined)){}
	if(this.so.getProperty("foo" == undefined)){}
	
	//Always assign unique ID's on the Server-Side because it's single threaded
	this.nextUserId = 0;
};
application.onStatus = function (info) {
	trace("onStatus> info.level: " + info.level + ", info.code: " + info.code);
	trace("onStatus> info.description: " + info.description);
	trace("onStatus> info.details: " + info.details);
};
application.onConnect = function (p_client, userName, password) {
	//A. Assign a uniqueID for any user who logs in
		//p_client.userId = this.nextUserId++;
		
	//B. Decide is a client needs a userName
	p_client.userName = userName;
	
	//C. Decide is you want to give a client user read/write access
		//p_client.writeAccess = "/public";
		//p_client.readAccess  = "/";

	//D. Inform the user that they have made a success connection
	application.acceptConnection(p_client);
	
	trace("onConnect> client.ip: " + p_client.ip);
	trace("onConnect> client.agent: " + p_client.agent);
	trace("onConnect> client.referrer: " + p_client.referrer);
	trace("onConnect> client.protocol: " + p_client.protocol);
};
application.onDisconnect = function (p_client) {
	//A. Clear any session variables that may pertain to a client user (SharedObject variables)
	trace("onDisconnect> client.userName: " + p_client.userName)
	trace("onDisconnect> disconnecting at: " + new Date( ));
};
/***************************
Shutdown
***************************/
application.onAppStop = function (info) {
	//A. For when the app stops
	trace("onAppStop> application.name: " + application.name);
	trace("onAppStop> stopping at " + new Date( ));
	trace("onAppStop> info.level: " + info.level);
	trace("onAppStop> info.code: " + info.code);
	trace("onAppStop> info.description: " + info.description);
};
/***************************
MidLife
***************************/
/*
Below are methods that any client can call. You are also able to write such methods within onConnect like:
	
	///////////////////////////////////////////////////
	application.onConnect = function(p_client){
		p_client.changeText = function(p_client){
			//Do Something
		}
	}
	///////////////////////////////////////////////////

The reason you may not want to do this is because every time a user connects, this function will be placed into memory. Therefore if many users connect, you could begin to fing issues with memory allocation so it's much more efficient to use the psuedo Javascript Class called prototype.
*/
Client.prototype.changeText = function(p_client){
	
}
Client.prototype.getStreamLength = function(p_streamName) {
	trace("Stream.length: " + p_streamName + ", " + Stream.length(p_streamName));
	return Stream.length(p_streamName);
}

ActionScript 应用发光滤镜

import flash.filters.GradientGlowFilter;

var gradientGlow:GradientGlowFilter = new GradientGlowFilter(0, 45, [2359295,0], [0, 1], [0, 123], 40, 40, 1, 1, "outer");
orb1.orb.filters=[gradientGlow];
/*FuseFMP.setFilterProps(orb1.orb, 'GradientGlow', {
GradientGlow_type:"outer",
GradientGlow_knockout:false,
GradientGlow_strength:1,
GradientGlow_quality:1,
GradientGlow_blur:20,
GradientGlow_ratios:"0,123",
GradientGlow_alphas:"0,1",
GradientGlow_colors:"2359295,0",
GradientGlow_angle:45,
GradientGlow_knockout:true,
GradientGlow_distance:0});*/
//FuseFMP.traceAllFilters()

/*trace("GradientGlow_type:"+FuseFMP.getFilterProp(orb1.orb,"GradientGlow_type" ));
trace( "GradientGlow_knockout:"+FuseFMP.getFilterProp(orb1.orb, "GradientGlow_knockout"));
trace("GradientGlow_strength:"+FuseFMP.getFilterProp(orb1.orb, "GradientGlow_strength"));
trace("GradientGlow_quality:"+FuseFMP.getFilterProp(orb1.orb, "GradientGlow_quality"));
trace("GradientGlow_blur:"+FuseFMP.getFilterProp(orb1.orb, "GradientGlow_blur"));
trace("GradientGlow_ratios:"+FuseFMP.getFilterProp(orb1.orb, "GradientGlow_ratios"));
trace("GradientGlow_alphas:"+FuseFMP.getFilterProp(orb1.orb, "GradientGlow_alphas"));
trace("GradientGlow_colors:"+FuseFMP.getFilterProp(orb1.orb, "GradientGlow_colors"));
trace("GradientGlow_angle:"+FuseFMP.getFilterProp(orb1.orb, "GradientGlow_angle"));
trace( "GradientGlow_distance:"+FuseFMP.getFilterProp(orb1.orb, "GradientGlow_distance"));*/

ActionScript AS2内部CSS解析

//A. Create CSS as a String
var css:String = ".headline {color: #FFCCCC; font-size: 18px}, p {color: #666666; font-size: 14px; font-weight: bold;}";

//B. Create a new Style Sheet & Parse the CSS
var ss = new TextField.StyleSheet();
ss.parseCSS(css);

//C. Create Some Strings
var headline:String = "<span class='headline'>Header 1</span><br>";
var p:String = "<p>lorem ipsum.....</p>";

//D. Create a Dynamic Text Field
var text_txt:TextField = this.createTextField("text_txt", this.getNextHighestDepth(), 0, 0, 100, 50);
text_txt.multiline = true;
text_txt.wordWrap = true;
text_txt.html = true;
text_txt.styleSheet = ss;

//E. Bind
text_txt.htmlText = headline + p;

ActionScript 非重复随机数

// ************************************************** // 
// Author: ImHugo
// URL: http://www.imhugo.com
// ************************************************** // 

// Vars
var arrayToRandom:Array = new Array();
var qRequired:Number = 5;

// Inserts Numbers in Array
for(var i:Number = 1; i<=qRequired; i++)
{
	arrayToRandom.push( i );
}

// Outputs numbers non-repeated
for(var k:Number = 1; k<=qRequired; k++)
{
	// Search for value inside the Array in a random position
	var randomPos:Number = Math.floor( Math.random() * arrayToRandom.length );
	
	// Selects value and removes it from Array
	var valueFromArray = arrayToRandom.splice(randomPos, 1);
	
	// Converts value in number
	var numberRand = parseInt(valueFromArray);
	
	trace(numberRand);
}