AS3常用代码片
来源:互联网 发布:视频管理源码 编辑:程序博客网 时间:2024/04/30 17:04
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~1tvmc.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");
- AS3常用代码片
- AS3常用代码片
- python常用代码片
- iOS - 常用代码片
- as3 常用代码集锦
- AS3常用代码
- Android常用实用功能代码片大全
- Java 的一些常用代码片
- Android常用实用功能代码片大全
- 常用的as3 代码段和技巧
- AS3常用位运算,提高代码效率
- 代码片
- 代码片
- 安卓常用实用功能代码片大全(长期更新)
- 常用的代码片,偶尔会用到时常更新吧
- AS3常用代码整理及细节优化注意
- 关于AS3代码异步执行问题的个人常用解决办法
- 常用贴片封装
- [IPhone]基于Flurry的用户行为统计
- ListView总结
- 关于jsp中<input type="file">获取路径问文件名,获取完全路径问题
- Mysql ON DUPLICATE KEY UPDATE 的 用法 简记
- 中国人的性格
- AS3常用代码片
- ios 下创建,删除文件夹的方法
- oracle over (partition by )用法
- IPhone开发的43个资源
- 刻画中国人的性格
- 重视性格的培养
- HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解
- 如何高效利用GitHub
- js里获得json对象里的值