加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

AS3常用代码片

发布时间:2020-12-15 18:22:19 所属栏目:百科 来源:网络整理
导读:1、全屏语句 stage.displayState = StageDisplayState.FULL_SCREEN;? 2、广播事件 //侦听事件EventDispatcherEx.dispatcher.addEventListener("returnManyou",ljTo);function ljTo(e){//ljt.gotoAndStop(p.frameNum);//执行相应的操作}//广播事件EventDispat

1、全屏语句

stage.displayState = StageDisplayState.FULL_SCREEN;?

2、广播事件

//侦听事件
EventDispatcherEx.dispatcher.addEventListener("returnManyou",ljTo);

function ljTo(e){
	//ljt.gotoAndStop(p.frameNum);
	//执行相应的操作	
}

//广播事件
EventDispatcherEx.dispatcher.dispatchEvent(new Event("returnManyou"));

//EventDispatcherEx 类
package {
	import flash.events.EventDispatcher;
	
	public class EventDispatcherEx{
		public static const dispatcher:EventDispatcher = new EventDispatcher;
		
		public function EventDispatcherEx(){
			
		}
	}
}

3、加载外部背景音乐并循环播放

import flash.media.SoundChannel;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.events.Event;

var soundM:Sound=new Sound();
var soundct:SoundChannel=new SoundChannel();
soundM.load(new URLRequest("bgmusic.mp3"));
soundct=soundM.play();
soundct.addEventListener(Event.SOUND_COMPLETE,onComplete);

function onComplete(eve:Event):void
{
	soundct=soundM.play();
	soundct.addEventListener(Event.SOUND_COMPLETE,onComplete);
} 

4、引用OSMultiTouch.swc库实现两点触摸效果

import com.lylib.touch.OSMultiTouch;
import com.lylib.touch.gestures.DirectionGesture;
import com.lylib.touch.events.DirectionEvent;
import com.lylib.touch.gestures.*;
import com.lylib.touch.events.ZoomEvent;
import com.lylib.touch.events.RotateEvent;
import com.lylib.touch.events.*;

var multiTouch:OSMultiTouch = OSMultiTouch.getInstance();

multiTouch.enableGesture (tvClip1,new ZoomGesture(),onZoomGesture); //缩放
multiTouch.enableGesture (tvClip1,new RotateGesture(),onRotateGesture); //旋转
multiTouch.enableGesture (tvClip1,new DragMoveGesture(),onDragGesture); //拖动

function onZoomGesture (e:ZoomEvent):void
{
	e.target.scaleX *=  e.deltaScale;
	e.target.scaleY *=  e.deltaScale;
}

function onRotateGesture (e:RotateEvent):void
{
	e.target.rotation +=  e.deltaAngle * 180 / Math.PI;
}

function onDragGesture (e:DragMoveEvent):void
{
	e.target.x +=  e.deltaOffsetX;
	e.target.y +=  e.deltaOffsetY;
}

5、fla中视频文件声音大小控制语言

//fla中视频音量控制
var ylkz:SoundTransform = new SoundTransform();
ylkz.volume = num;   //num为你想要的音量大小0~1
tvmc.soundTransform = ylkz;   //tvmc 为加载了一个视频的MovieClip影片

6、在卸载子swf时清空内存(听说不算好,但好像还是有用的)

function GC() 
{
    try { 
         var lc1:LocalConnection = new LocalConnection(); 
         var lc2:LocalConnection = new LocalConnection(); 
         lc1.connect('name'); 
         lc2.connect('name2'); 
    }catch (e:Error){ 
        
	} 
}

7、360度序列帧拨动播放

stop();
var preMouse:Number; //鼠标位置
var frameNum:int = 1; //当前帧
var dist:Number = 8; //在屏上滑动多远距离跳一帧 
this.addEventListener(MouseEvent.MOUSE_DOWN,downHandler);
this.addEventListener(MouseEvent.MOUSE_UP,upHandler);
this.addEventListener(MouseEvent.MOUSE_OUT,outHandler);

function downHandler(event:MouseEvent):void
{
	preMouse = mouseX;
	this.addEventListener(MouseEvent.MOUSE_MOVE,moveHandler);
}

function moveHandler(event:MouseEvent):void
{
	if(mouseX - preMouse > dist)
	{
		frameNum ++;
		if(frameNum < totalFrames){
			this.nextFrame();
		}else{
			this.gotoAndStop(1);
			frameNum = 1;
		}
		preMouse = mouseX;
	}
	
	if(mouseX - preMouse < -dist)
	{
		frameNum --;
		if(frameNum > 1){
			this.prevFrame();
		}else{
			this.gotoAndStop(totalFrames);
			frameNum = totalFrames;
		}
		preMouse = mouseX;
	}
}

function upHandler(event:MouseEvent):void
{
	this.removeEventListener(MouseEvent.MOUSE_MOVE,moveHandler);
}

function outHandler(event:MouseEvent):void
{
	this.removeEventListener(MouseEvent.MOUSE_MOVE,moveHandler);
}

?

2013-08-16

字符串去掉前后空格

//var src:String=" Hello! ";  
//trace("""+src+""");    //原文本  
//trace("""+src.replace(/^s*/g,"")+""");    //去掉前面的空格  
//trace("""+src.replace(/s*$/g,"")+""");    //去掉后面的空格 

?

2014-05-04

保存图片到本地,有弹出文件保存框的方式,主要用到FileReference类,感谢 flash023

//import com.adobe.images.JPGEncoder;
function save(defaultFileName:String = null):void {
        var _fileRef:FileReference=new FileReference();//用于保存文件
        var _encoder:JPGEncoder=new JPGEncoder(80);//用于编码位图
        var bitmapData:BitmapData=new BitmapData(stage.stageWidth,stage.stageHeight);
        bitmapData.draw(this);//得到位图
        var ba:ByteArray=_encoder.encode(bitmapData);//编码成JPG图片,质量为80
        _fileRef.save(ba,defaultFileName);//保存到磁盘,会出现个系统保存对话框。
        ba.clear();
}
function onClick(_evt:MouseEvent ):void {
        save("flash023.jpg");
}
bg.addEventListener("click",onClick);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读