AS3常用代码片

9 篇文章 0 订阅

1、全屏语句

stage.displayState = StageDisplayState.FULL_SCREEN; 

2、广播事件

[html]  view plain copy
  1. //侦听事件  
  2. EventDispatcherEx.dispatcher.addEventListener("returnManyou", ljTo);  
  3.   
  4. function ljTo(e){  
  5.     //ljt.gotoAndStop(p.frameNum);  
  6.     //执行相应的操作     
  7. }  
  8.   
  9. //广播事件  
  10. EventDispatcherEx.dispatcher.dispatchEvent(new Event("returnManyou"));  
  11.   
  12. //EventDispatcherEx 类  
  13. package {  
  14.     import flash.events.EventDispatcher;  
  15.       
  16.     public class EventDispatcherEx{  
  17.         public static const dispatcher:EventDispatcher = new EventDispatcher;  
  18.           
  19.         public function EventDispatcherEx(){  
  20.               
  21.         }  
  22.     }  
  23. }  

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

[html]  view plain copy
  1. import flash.media.SoundChannel;  
  2. import flash.media.Sound;  
  3. import flash.net.URLRequest;  
  4. import flash.events.Event;  
  5.   
  6. var soundM:Sound=new Sound();  
  7. var soundct:SoundChannel=new SoundChannel();  
  8. soundM.load(new URLRequest("bgmusic.mp3"));  
  9. soundct=soundM.play();  
  10. soundct.addEventListener(Event.SOUND_COMPLETE,onComplete);  
  11.   
  12. function onComplete(eve:Event):void  
  13. {  
  14.     soundct=soundM.play();  
  15.     soundct.addEventListener(Event.SOUND_COMPLETE,onComplete);  
  16. }   

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

[html]  view plain copy
  1. import com.lylib.touch.OSMultiTouch;  
  2. import com.lylib.touch.gestures.DirectionGesture;  
  3. import com.lylib.touch.events.DirectionEvent;  
  4. import com.lylib.touch.gestures.*;  
  5. import com.lylib.touch.events.ZoomEvent;  
  6. import com.lylib.touch.events.RotateEvent;  
  7. import com.lylib.touch.events.*;  
  8.   
  9. var multiTouch:OSMultiTouch = OSMultiTouch.getInstance();  
  10.   
  11. multiTouch.enableGesture (tvClip1, new ZoomGesture(), onZoomGesture); //缩放  
  12. multiTouch.enableGesture (tvClip1, new RotateGesture(), onRotateGesture); //旋转  
  13. multiTouch.enableGesture (tvClip1, new DragMoveGesture(), onDragGesture); //拖动  
  14.   
  15. function onZoomGesture (e:ZoomEvent):void  
  16. {  
  17.     e.target.scaleX *=  e.deltaScale;  
  18.     e.target.scaleY *=  e.deltaScale;  
  19. }  
  20.   
  21. function onRotateGesture (e:RotateEvent):void  
  22. {  
  23.     e.target.rotation +=  e.deltaAngle * 180 / Math.PI;  
  24. }  
  25.   
  26. function onDragGesture (e:DragMoveEvent):void  
  27. {  
  28.     e.target.x +=  e.deltaOffsetX;  
  29.     e.target.y +=  e.deltaOffsetY;  
  30. }  

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

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

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

[html]  view plain copy
  1. function GC()   
  2. {  
  3.     try {   
  4.          var lc1:LocalConnection = new LocalConnection();   
  5.          var lc2:LocalConnection = new LocalConnection();   
  6.          lc1.connect('name');   
  7.          lc2.connect('name2');   
  8.     }catch (e:Error){   
  9.           
  10.     }   
  11. }  

7、360度序列帧拨动播放

[html]  view plain copy
  1. stop();  
  2. var preMouse:Number; //鼠标位置  
  3. var frameNum:int = 1; //当前帧  
  4. var dist:Number = 8; //在屏上滑动多远距离跳一帧   
  5. this.addEventListener(MouseEvent.MOUSE_DOWN,downHandler);  
  6. this.addEventListener(MouseEvent.MOUSE_UP,upHandler);  
  7. this.addEventListener(MouseEvent.MOUSE_OUT,outHandler);  
  8.   
  9. function downHandler(event:MouseEvent):void  
  10. {  
  11.     preMouse = mouseX;  
  12.     this.addEventListener(MouseEvent.MOUSE_MOVE,moveHandler);  
  13. }  
  14.   
  15. function moveHandler(event:MouseEvent):void  
  16. {  
  17.     if(mouseX - preMouse > dist)  
  18.     {  
  19.         frameNum ++;  
  20.         if(frameNum < totalFrames){  
  21.             this.nextFrame();  
  22.         }else{  
  23.             this.gotoAndStop(1);  
  24.             frameNum = 1;  
  25.         }  
  26.         preMouse = mouseX;  
  27.     }  
  28.       
  29.     if(mouseX - preMouse < -dist)  
  30.     {  
  31.         frameNum --;  
  32.         if(frameNum > 1){  
  33.             this.prevFrame();  
  34.         }else{  
  35.             this.gotoAndStop(totalFrames);  
  36.             frameNum = totalFrames;  
  37.         }  
  38.         preMouse = mouseX;  
  39.     }  
  40. }  
  41.   
  42. function upHandler(event:MouseEvent):void  
  43. {  
  44.     this.removeEventListener(MouseEvent.MOUSE_MOVE,moveHandler);  
  45. }  
  46.   
  47. function outHandler(event:MouseEvent):void  
  48. {  
  49.     this.removeEventListener(MouseEvent.MOUSE_MOVE,moveHandler);  
  50. }  

 

2013-08-16

字符串去掉前后空格

[java]  view plain copy
  1. //var src:String=" Hello! ";    
  2. //trace("\""+src+"\"");    //原文本    
  3. //trace("\""+src.replace(/^\s*/g,"")+"\"");    //去掉前面的空格    
  4. //trace("\""+src.replace(/\s*$/g,"")+"\"");    //去掉后面的空格
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值