ActionScript 带有ClickTag模板的AS2横幅

// see the source files found in the zip in the URL above.
// Thanks to Nate63179 for the idea of ClickTag URL rollover
// http://snipplr.com/view/14239/actionscript-20-click-tag-handler/

ActionScript 交换深度

on (press, release, dragOver, dragOut) {
	_root.x +=2;
	_root.green.swapDepths(_root.x);
}

ActionScript AS2调试脚本

debugg("testing");


//**************************** BEGIN DEBUG FUNCTION
function debugg(whichText:String)
{
	debug_txt.text += "\n\n" + whichText;
	trace("\n\n" + whichText + "\n\n");
}

onEnterFrame = function() {
	if ((Key.isDown(Key.BACKSPACE))) {
		if ((Key.isDown(Key.LEFT))) {
			if (Key.getCode() == 17) { // so, press BACKSPACE+LEFT, and CONTROL (in that order, together) to reveal the debug
				debug_txt._y = Stage.height / 2;
			}
	   	}
   	}
};
//**************************** END DEBUG FUNCTION

ActionScript FLASH - 加载图像loadClip

var imageListener:Object = new Object();
imageListener.onLoadInit = function() {
			var aimageTween:Tween = new Tween(holder_mc, "_alpha", Regular.easeOut, 0, 100, 1, true); 
		}
var imageLoader:MovieClipLoader = new MovieClipLoader();
imageLoader.addListener(imageListener);
imageLoader.loadClip("/photos/filename.png", holder_mc);

ActionScript 将样式应用于Actionscript 2中的文本字段的简便方法

///////put this somewhere with your other functions//////
TextField.prototype.applyStyles=function(styles){
	fmt = new TextFormat();
	for (var key:String in styles){
		fmt[key]=styles[key];
	}
	this.setTextFormat(fmt);
}



////////pass in an object with all the styles you want
myTextField.applyStyles({color:"0xFFFFFF",letterSpacing:-2,bold:true,size:18});








/* here's some other styles (flash8)

myTextField2.applyStyles({
align:"center",
blockIndent:10, //indents the text block 10pt
bullet:true;
font:"Gill Sans",
indent:"3", //indents first character 3pt
italic:true,
kerning:true, //kerning enabled
leading:15, //15 pixels (line spacing)
leftMargin: 10, //10 point left margin
leftMargin: 10, //10 point right margin
underline:true,
color:"0xFFFFFF",
letterSpacing:-2,
bold:true,
size:18
});

*/

ActionScript AS2:位图更平滑

import flash.display.*;

function loadBitmapSmoothed(url:String, target:MovieClip) {
	// Create a movie clip which will contain our unsmoothed bitmap
	var bmc:MovieClip = target.createEmptyMovieClip("bmc",target.getNextHighestDepth());

	// Create a listener which will notify us when the bitmap loaded successfully
	var listener:Object = new Object();
	// Track the target
	listener.tmc = target;
	
	// If the bitmap loaded successfully we redraw the movie into
	// a BitmapData object and then attach that BitmapData to the target
	// movie clip with the smoothing flag turned on.
	listener.onLoadInit = function(mc:MovieClip) {
		var mc:MovieClip = mc;
		mc._visible = false;
//		mc.forceSmoothing
		var bitmap:BitmapData = new BitmapData(mc._width, mc._height, true);
		this.tmc.attachBitmap(bitmap, this.tmc.getNextHighestDepth(),"auto", true);
		bitmap.draw(mc);
	};
	
	// Do it, load the bitmap now
	var loader:MovieClipLoader = new MovieClipLoader();
	loader.addListener(listener);
	loader.loadClip(url, bmc);
}

// Sample code

createEmptyMovieClip("mc1", getNextHighestDepth());
mc1.createEmptyMovieClip("mc", mc1.getNextHighestDepth());

//mc1.mc.loadMovie("flash.png");
loadBitmapSmoothed("http://digitallibrary.usc.edu/assetserver/controller/rendition/VIT-001470/page-1", mc1.mc);

mc1.onEnterFrame = function() {
	// Ugly, but we are not using a MovieClipLoader for the unsmoothed case
	mc1.mc._x = -150;
	mc1.mc._y = -230;
	mc1._x = Stage.width / 2;
	mc1._y = Stage.height / 2;
	mc1._rotation += 0.5;
}

ActionScript 选择文本字段内容并从之前选择的文本字段中删除选择。对于AS2

input.onSetFocus = function(old:TextField):Void  {
			 Selection.setSelection(0, 0);
			 var lo:Object = new Object();
			 lo.tf = this;
			lo.onMouseUp = function() {
				trace(this.tf);
				Selection.setSelection(0, this.tf.text.length);
				Mouse.removeListener(this);
			};
				Mouse.addListener(lo);
		 };

ActionScript 酷动画效果

import com.greensock.*;

function tweenElements(arr:Array, last:Boolean){
    var tweens= [];
    for(var i=0; i<arr.length; i++){
        var tgt = arr[i];
        var mult = i%2==0?1:-1;
        tgt._alpha = 0;
         t = TweenLite.to(tgt, .5, {_x:getTX(tgt, mult), _alpha:100, onStart:onAnimStart, onStartParams:[tgt,i, mult], delay:.2*i, onComplete:function(){
           if(last) return;
           setInterval(function(){
               var t2 = tweens.shift()
               t2.reverse();
           }, 2000);
           
        }});
        tweens.push(t);
        
        if(last){
            TweenLite.to(bottombar, .5, {_y:235.5, _alpha:100, onStart:function(){
                bottombar._visible = true;
            }, delay:2})
        }
        
    }
}



var tgtX;
function getTX(tgt, mult){
    tgtX = tgt._x;
    tgt._x -= mult*40;
    return tgtX;
}

ActionScript AS2 Self Preloader

// Frame 1
var total_bytes = _root.getBytesTotal();
var loaded_bytes = _root.getBytesLoaded();
percent = loaded_bytes/total_bytes;

if(percent >=1) gotoAndPlay("_afterLoad");



// Frame 2
gotoAndPlay(1);

ActionScript 多次调整大小和重新定位

stop();
import flash.geom.Matrix;
import com.orazal.oralib2.transitions.MultiTweener;
import com.robertpenner.easing.*;


var totalItems:Number = 5;
var itemWidth:Number = 330;
var totalWidth:Number = 875;
var thumbSpacing:Number = 2;
var adjustedWidth:Number = totalWidth - (thumbSpacing * (totalItems-1));
var thumbWidth:Number = adjustedWidth /totalItems;
var smallThumbWidth:Number = (adjustedWidth-itemWidth)/4;
var itemList:Array = [item0, item1, item2, item3, item4];
var activeItem:MovieClip = null;

// Init
placeThumbs();

function placeThumbs(){
	
	// Go through itemList
	for(var i:Number=0; i<itemList.length; i++)
	{
		var item:MovieClip = itemList[i];
		
		// Original size & position
		item.originalMatrix = item.transform.matrix;
		item.originalMatrix.tx = (smallThumbWidth*i) + (thumbSpacing*i);
		
		// Small thumb size 
		item.smallThumbMatrix = item.transform.matrix;
		item.smallThumbMatrix.a = item.smallThumbMatrix.d = smallThumbWidth/itemWidth;
		
		// Thumb size & position
		item.thumbMatrix = item.transform.matrix;
		item.thumbMatrix.a = item.thumbMatrix.d = thumbWidth/itemWidth;
		item.thumbMatrix.tx = (thumbWidth*i) + (thumbSpacing*i);
		item.transform.matrix = item.thumbMatrix;
		
		item.onRelease = function()
		{
			itemReleaseHandler(this);
		}
	}
}

function itemReleaseHandler(item:MovieClip)
{
	// If it's already selected
	if(activeItem == item)
	{
		activeItem = null;
		// close all
		for(var i:Number=0; i<itemList.length; i++)
		{
			var clip:MovieClip = itemList[i];
			tweenToThumb(clip);
		}
		return;
	}
	
	// If none or another one is selected
	if(activeItem != this)
	{
		activeItem = item;
		tweenToOriginal(item);
		
		var position:Number = Number(item._name.substr(4));
		for(var i:Number=0; i<itemList.length; i++)
		{
			var clip:MovieClip = itemList[i];
			// Left of active
			if(i < position)
			{
				clip.smallThumbMatrix.tx = (smallThumbWidth*i) + (thumbSpacing*i);
				tweenToSmallThumb(clip);
			}
			// Right of active
			if(i > position)
			{
				clip.smallThumbMatrix.tx = (smallThumbWidth*(i-1)) + (thumbSpacing*i);
				clip.smallThumbMatrix.tx += itemWidth;
				tweenToSmallThumb(clip);
			}
		}
		return;
	}

}

function tweenToOriginal(item:MovieClip)
{
	item.tween.stop();

	var startMatrix:Matrix = item.transform.matrix;
	var endMatrix:Matrix = item.originalMatrix;
	item.tween = new MultiTweener(startMatrix, endMatrix, 
								  Circ.easeOut, 0.5, true);
	item.tween.onMotionChanged = function(mt:MultiTweener) {
		item.transform.matrix = startMatrix;
	}
}

function tweenToThumb(item:MovieClip)
{
	item.tween.stop();
	var startMatrix:Matrix = item.transform.matrix;
	var endMatrix:Matrix = item.thumbMatrix;
	item.tween = new MultiTweener(startMatrix, endMatrix, 
								  Circ.easeOut, 0.5, true);
	item.tween.onMotionChanged = function(mt:MultiTweener) {
		item.transform.matrix = startMatrix;
	}
}

function tweenToSmallThumb(item:MovieClip)
{
	item.tween.stop();
	var startMatrix:Matrix = item.transform.matrix;
	var endMatrix:Matrix = item.smallThumbMatrix;
	item.tween = new MultiTweener(startMatrix, endMatrix, 
								  Circ.easeOut, 0.5, true);
	item.tween.onMotionChanged = function(mt:MultiTweener) {
		item.transform.matrix = startMatrix;
	}
}