ActionScript 3 Papervision3D - distanceTo()

//returns the distance between the two objects.
trace(myFirstObject.distanceTo(myOtherObject));

ActionScript 3 功能获取矩形中的随机点

public function getRandomPoint(rectangle){
    var randomX = getRandomInteger(rectangle.left, rectangle.right);
    var randomY = getRandomInteger(rectangle.top, rectangle.bottom);

    return new Point(randomX, randomY);

  function getRandomInteger (min, max) {
    return min + Math.floor(Math.random()*(max + 1 - min));
  }
}

ActionScript 3 滴答作响的时钟

var myTimer:Timer = new Timer(1000);

myTimer.start(); 
myTimer.addEventListener(TimerEvent.TIMER, timerHandler);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, completeHandler);

function timerHandler(e:TimerEvent):void{
        
		var current:Date = new Date();

		trace(current);  
}

function completeHandler(e:TimerEvent):void {
             
}

ActionScript 3 EZ·A ?? - 当 å‰??网址

var urlPath = ExternalInterface.call('eval', 'window.location.href');
ExternalInterface.call('alert',urlPath);

ActionScript 3 æ»江局长?¡å¶ä½œ

tuodongtiao.addEventListener(MouseEvent.MOUSE_DOWN, _onDrag);
private function _onDrag(e:MouseEvent)
{
	var t:MovieClip = MovieClip(e.target);
	t.startDrag(false, new Rectangle(430, 0, 0, 400));
        t.addEventListener(Event.ENTER_FRAME, _onDragerEnterFrame);
	stage.addEventListener(MouseEvent.MOUSE_UP, _onStopDrag);
}
private function _onStopDrag(e:MouseEvent)
{
	stage.removeEventListener(MouseEvent.MOUSE_UP, _onStopDrag);
	tuodongtiao.stopDrag();
}
private function _onDragerEnterFrame(e:Event)
{
	var t:MovieClip = MovieClip(e.target);
	var delta = t.y * (car.lingdong.ceng.wenziMc.wenzi.textHeight - 380) / 400;
	if (delta > 0)
	{
		car.lingdong.ceng.wenziMc.y = car.lingdong.ceng.wenziMc.originY - delta; 
	}
}

ActionScript 3 随机范围

private function randRange(minNum:Number, maxNum:Number):Number 
        {
            return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
        }

ActionScript 3 AS3:UTF8字符串中有多少字节

var string:String = "i am testing how many bytes ther are in this particular tweet.  I'm hoping it's roughly 255 because I will have answered the secret to life.";
 function getNumBytesUTF8 (s:String):Number {
  var byteArray:ByteArray = new ByteArray();
  byteArray.writeUTFBytes(s);
  return byteArray.length;
}
// Usage:
trace(getNumBytesUTF8( string ));  // 255

ActionScript 3 如何使用按钮

stop();
import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.events.MouseEvent;
var getYouTube:URLRequest = new	URLRequest("http://www.youtube.com");

/// B Button Get a URL ///
B_btn.addEventListener(MouseEvent.CLICK, bClick);
function bClick(event:MouseEvent):void{
	navigateToURL(getYouTube);
}
					

/// G Button Property ///

G_btn.addEventListener(MouseEvent.CLICK, gClick);
G_btn.addEventListener(MouseEvent.MOUSE_OUT, gOut);

function gClick(event:MouseEvent):void{
	gotoAndStop("getJargon");
}
function gOut(event:MouseEvent):void{
	gotoAndStop(1);
}


/// R Button Property ///

R_btn.addEventListener(MouseEvent.CLICK, rClick);
R_btn.addEventListener(MouseEvent.MOUSE_OUT, rOut);


function rClick(event:MouseEvent):void{
	R_btn.alpha -= 0.1;
}
function rOut(event:MouseEvent):void{
	R_btn.alpha = 1;
}

ActionScript 3 带有Zin init的基类模板

package
{
	
	import flash.display.Sprite;
	import flash.system.Capabilities;
	import mdm.*;
	
	public class Main extends Sprite
	{
		
		public var isZinc:Boolean;
		
		/* _____________________________________________________________________________
		 * 
		 * CONSTRUCTOR
		 * 
		 */
		public function Main() 
		{
			mdm.Application.init( this, onMDMinit );
		}
		
		private function onMDMinit():void
		{
			isZinc = ( Capabilities.playerType == "ActiveX" ) ? true : false ;
		}
	}
	
}

ActionScript 3 绘制像素箭头

// Draw left and right arrows
// Pass through the graphics layer of an Sprite

public static function drawLeft(pGraphics : Graphics) : void {
			
	pGraphics.moveTo(0, 0);
	pGraphics.drawRect(0, 0,5,1);
	pGraphics.drawRect(1, -1,1,1);
	pGraphics.drawRect(2, -2,1,1);
	pGraphics.drawRect(1, 1,1,1);
	pGraphics.drawRect(2, 2,1,1);
}

public static function drawRight(pGraphics : Graphics) : void {
	
	pGraphics.moveTo(0, 0);
	pGraphics.drawRect(0, 0,5,1);
	pGraphics.drawRect(4, -1,1,1);
	pGraphics.drawRect(3, -2,1,1);
	pGraphics.drawRect(4, 1,1,1);
	pGraphics.drawRect(3, 2,1,1);
}