AS3常用代码片

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);

 

2016-08-10 

根据url打开浏览器

 

var url:URLRequest = new URLRequest("http://www.shao-ming.cn");
 navigateToURL(url,"_blank");

2019-08-15

AS3 mc转换成Bitmap

将mc转换成bitmap首先得建立一个BitmapData,使用BitmapData的draw方法或是BitmapData.copyPixels方法绘制。 
var mc:MovieClip = new MovieClip(); 
var mBit:BitmapData = new BitmapData(mc.width,mc.height, true, 0xffffff); 
mBit.draw(mc); 
var bitmap:Bitmap = new Bitmap(mBit);


 

 

 

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
-判断矢量边缘实现不规则物品碰撞检测(非位图) -高效位图碰撞及重叠矢量检测 -A星,深/广度,2D/3D/路点,寻路方式统一处理。 -二次贝尔法曲线,按长度切割和计算法线,光滑曲线拟合(过点或者不过点) -SWF解析器,从ByteArray中播放声音,直接控制AVM1的动画类容。 -丰富的文本缓动,部分文字Filter,渐变色文字,字符差异对比,ANSI转码,URL解码,中文数字,拼音码,这是一个单独的底层包 -完全由FLASH实现的拼音输入法,需要加载200K的词库,光标跟随并可词语输入(感觉和智能ABC差不多) -缩略图,倒影,梯形变换,马赛克,各种特效,火焰什么的 -完整功能的自定制过渡,不仅能用,也能创造。如果不会用,可以使用Creater中的模板 -粒子,物理,景深 -像QQ那样截屏! -流方式读取文本和图。HTML可以,FLASH也可以 -和FXG类似的道理,用对象保存绘制操作,简化绘制过程 -多种拖拽工具,变形工具,编辑形状工具。单个拖动点也可单独使用。 -单文件自加载 -右键,双击,三击,键盘管理,鼠标手势 -影子生成器。FLASH也是可以模拟出效果不错的光影的。影子可以折墙壁 -防客户端修改解决方案(内存修改,加速) -切割图形,同时支持矢量,位图,而且,你可以按45度角来切! -颜色模式转换 -去背景,魔法棒 -图文混排的简单实现。也可以显示Table表格 -滤镜代理:修改了滤镜的属性便能立即生效,你可以直接对它Tween!当然,水波放大镜,对比度饱和度顺便也提供了。 -常用的JS扩展:IFrame,便捷的提供接口给外部JS,调用浏览器音乐播放器播放MID,以及一些常用的防刷新,防鼠标滚轮干扰。当然,deeplink是不可少的。 -扇形,圆环,虚线 -四则运算(字符串分析)

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jswm20150115

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值