ActionScript 3 网络服务

public var WebserviceURL:String;
public var service:WebService;

public function accessWebService():void
{
		service 	  = new WebService();
		WebserviceURL = "http://mywebserver.net/webService.asmx?wsdl";
		service.wsdl  = WebserviceURL;
		service.addEventListener(ResultEvent.RESULT,webServiceResultHandler);
		
		service.loadWSDL();
		service.GetCallHistory(username, 1, PageNo);

}

public function webServiceResultHandler(event:ResultEvent):void
{
	var result:ArrayCollection = event.result as ArrayCollection;
	dgVideoHistory.dataProvider = result;
}

ActionScript 3 使用ActionScript 3暂停框架

stop();

var timer:Timer = new Timer(10000, 1);
timer.addEventListener(
  TimerEvent.TIMER,
  function(evt:TimerEvent):void {
    play();
  }
);
timer.start();

ActionScript 3 忽略AIR中的隐藏文件

private function iterateFiles(dir:File):void
{
    if (!dir.isDirectory || dir.isHidden || !dir.exists || dir.name.search(/^\..*$/) != -1) return;
    var listing:Array = dir.getDirectoryListing();
    for each(var f:File in listing)
    {
        if (this.fileList.length >= this.MAX_FILES) break;
        if (f.isHidden || !f.exists || f.name.search(/^\..*$/) != -1) continue;
        if (f.isDirectory)
        {
            this.iterateFiles(f);
        }
        else
        {
            this.fileList.push(f);
        }
    }
}

ActionScript 3 全部替换

private function replace(org:String, fnd:String, rpl:String):String
{
	return org.split(fnd).join(rpl);
}

ActionScript 3 浮雕3d

package {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.BitmapDataChannel;
	import flash.display.BlendMode;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.geom.ColorTransform;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.geom.Rectangle;

	public class Work extends Sprite
	{
		[Embed(source="image.jpg")]
		private var Image1:Class;

		[Embed(source="alpha.jpg")]
		private var Image2:Class;


		private var tx:Number = 10;
		private var ty:Number = 10;
		
		public function Work()
		{
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP;
			test1();
			test2();
			test3();
		}
		
		private function test1():void
		{
			var source:BitmapData = (new Image1() as Bitmap).bitmapData;

			var offset:Matrix = new Matrix();
			
			var bmd:BitmapData = new BitmapData(source.width-tx,source.height-ty,source.transparent,0xFF0000);

 			bmd.copyChannel(source,new Rectangle(tx,ty,source.width,source.height),new Point(0,0), BitmapDataChannel.RED,BitmapDataChannel.RED);
			bmd.draw(source,offset, new ColorTransform(0),BlendMode.DIFFERENCE );
			
			addChild( new Bitmap(bmd) );			
		}


		private function test2():void
		{
			var source:BitmapData = (new Image1() as Bitmap).bitmapData;

			var offset:Matrix = new Matrix();
			offset.translate(tx,ty);
			
			var bmd:BitmapData = source.clone();

 			bmd.copyChannel(source,source.rect,new Point(0,0), BitmapDataChannel.BLUE,BitmapDataChannel.RED);
 			bmd.copyChannel(source,source.rect,new Point(0,0), BitmapDataChannel.GREEN,BitmapDataChannel.RED);

 			bmd.copyChannel(source,source.rect,new Point(-tx,-ty), BitmapDataChannel.ALPHA,BitmapDataChannel.ALPHA);
 			bmd.copyChannel(source,source.rect,new Point(-tx,-ty), BitmapDataChannel.RED,BitmapDataChannel.RED);
			
			addChild( new Bitmap(bmd) ).y = 200;			
		}
		
		private function test3():void
		{
			var source:BitmapData = (new Image2() as Bitmap).bitmapData;

			var offset:Matrix = new Matrix();
			offset.translate(tx,ty);
			
			var bmd:BitmapData = source.clone();

 			bmd.copyChannel(source,source.rect,new Point(0,0), BitmapDataChannel.BLUE,BitmapDataChannel.RED);
 			bmd.copyChannel(source,source.rect,new Point(0,0), BitmapDataChannel.GREEN,BitmapDataChannel.RED);
 			bmd.copyChannel(source,source.rect,new Point(-tx,-ty), BitmapDataChannel.ALPHA,BitmapDataChannel.ALPHA);
 			bmd.copyChannel(source,source.rect,new Point(-tx,-ty), BitmapDataChannel.RED,BitmapDataChannel.RED);
			
			addChild( new Bitmap(bmd) ).y = 400;			
		}

	}
}

ActionScript 3 AS3 - 检查字符串是否为true / false

//Recieves a string, checks to see if it is true/false, passes boolean back
function checkBoolean(val:String):Boolean {
	if (val.toLowerCase() == "true") { 
		return true; 
	} else { 
		return false; 
	}
}

ActionScript 3 Text String Clipper类

/**
    Text String Clipper class
    author: Blaine Joubert
    version: 0.1
    modified: 04/08/2009
   
	
	Adds a ... to the end of a text string if its too long
	
	To use: Import Class then use
	var textClip:TextClipper = new TextClipper (cutOffCharLength, textFieldName, textFieldCharLength, textContent)

*/

package {
    import flash.display.*;
    import flash.text.*;
	

	public class TextClipper extends MovieClip {
		
		//--------------------------------------
		// PUBLIC VARIABLES
		//--------------------------------------
		
		public var _cutOffCharLength:int
		public var _textFieldName:TextField
		public var _textFieldCharLength :int
		public var _textContent:String
		
		//--------------------------------------
		// CONSTRUCTOR
		//--------------------------------------
		
		public function TextClipper(cutOffCharLength:int, textFieldName:TextField, textFieldCharLength:int, textContent:String ):void {
			
			_cutOffCharLength       =  cutOffCharLength;
			_textFieldName   		=  textFieldName;
			_textFieldCharLength 	=  textFieldCharLength;
			_textContent     		=  textContent;
			
			Init();

		}
		
		public function Init():void {
			
			
			
			if (_textFieldCharLength >= _cutOffCharLength) {
					
					_textFieldName.replaceText(_cutOffCharLength, _textFieldCharLength, "...");
				
				}else {
					
					_textFieldName.text =  _textContent
			}
				
		}	
	}

}

ActionScript 3 RemoteService

public function RemoteService( serviceId:String
, serviceDestination:String
, amfChannelId:String
, amfChannelEndpoint:String
)
{
// Create a runtime Channelset for given Channel ID and Endpoinr URI
var amfChannel:AMFChannel = new AMFChannel(amfChannelId, amfChannelEndpoint);
amfChannelSet = new ChannelSet();
amfChannelSet.addChannel(amfChannel);
// Create the remoteObject instance
this.remoteObject = new RemoteObject(serviceId);
this.remoteObject.channelSet = amfChannelSet;
this.remoteObject.destination = serviceDestination;
this.remoteObject.addEventListener(FaultEvent.FAULT,onRemoteException);
}

ActionScript 3 AS3序列化

flash.net.registerClassAlias( alias:String, classObject:Class );

ActionScript 3 循环通过类的常量属性

for each (var constant:XML in describeType(ClassName).constant) 
{
   var property:String = ClassName[constant.@name];		
}