• 你知之甚少的actionscript3


      1 1.缩略的条件表达式short conditional statements
    2 var someVar:Number;
    3 if(someVar)
    4 doSomething();
    5 2.缩略的构造函数short constructors
    6 var point:Point = new Point;
    7 3.throw不光用于抛出错误,还可以抛出对象Throwing objects
    8 try
    9 {
    10 throw 1;
    11 }
    12 catch(n:Number)
    13 {
    14 trace(n); //outputs 1
    15 }
    16 4.arguments的一种特殊使用(arguments.callee代表arguments所在的函数) Arguments class
    17 this.addEventListener('eventt',
    18 function(event:Event):void
    19 {
    20 event.target.removeEventListener(event.type,arguments.callee);
    21 trace(arguments.callee);
    22 }
    23 );
    24 this.dispatchEvent(new Event('eventt'));
    25 5.||= 逻辑或赋值(如果一个变量的值存在,则不赋新值给该变量,如果该值不存在,则赋值给该变量)logical or assignment
    26 var num:Number;
    27 num ||= 10;
    28 trace(num); // outputs 10
    29
    30 num = 5;
    31 trace(num); // outpus 5
    32
    33 num ||= 10;
    34 trace(num); //outpus 5
    35 trace(10 || 5);
    36 6.获取指定对象的类构造函数Getting object class type
    37 var obj:Sprite = new Sprite();
    38 var clazz:Class = Object(obj).constructor;
    39 trace(new clazz());
    40 7.循环标签和continue的使用Labels & continue
    41 var outerArray:Array = [1,2,3];
    42 var innerArray:Array = [2,3,4];
    43 outerLoop:for (var i:uint = 0;i < outerArray.length; ++i)
    44 {
    45 var foo:String = outerArray[i];
    46 innerLoop:for(var j:uint = 0; j< innerArray.length; ++j)
    47 {
    48 var bar:String = innerArray[j];
    49 if( foo == bar )
    50 {
    51 continue outerLoop;
    52 }
    53 }
    54 trace(foo); //
    55 }
    56 8.Label & break
    57 dateCheck:
    58 {
    59 trace('good morning')
    60 var today:Date = new Date();
    61 if(today.month == 9 && today.date == 11)
    62 {
    63 break dateCheck;
    64 }
    65 trace('time for work');
    66 }
    67 9.with的使用with statement
    68 function polar(r:Number):void
    69 {
    70 var a:Number,x:Number,y:Number;
    71 with(Math)
    72 {
    73 a= PI * pow(r,2);
    74 x = r * cos(PI);
    75 y = r *sin(PI/2);
    76 }
    77 trace('acos'+a);
    78 trace('x-'+x);
    79 trace('y-'+y);
    80 }
    81 polar(3);
    82 10.像trace一样的全局函数global functions
    83 //globalFunction.as file
    84 package
    85 {
    86 public function globalFunction(text:String):void
    87 {
    88 trace(text);
    89 }
    90 }
    91 11.包内函数internal functions
    92
    93 protected function someFunction():void
    94 {
    95 var internalFunction:Function = function(text:String):void
    96 {
    97 trace(text);
    98 }
    99
    100 internalFunction('Hello world');
    101 }
    102 12.命名空间custom namespaces
    103 //online.as file
    104 package org.corlan
    105 {
    106 public namespace online = 'http://www.baidu.com';
    107 }
    108 //offline.as file
    109 package org.corlan
    110 {
    111 public namespace offline = 'http://www.sdo.com/';
    112 }
    113
    114 online function save(object:Object):void
    115 {
    116 trace('online');
    117 }
    118
    119 offline function save(object:Object):void
    120 {
    121 trace('offline');
    122 }
    123
    124 online::save(obj);
    125 offline::save(obj);
    126
    127 13.代理类Proxy class
    128 import flash.utils.Proxy;
    129
    130 dynamic class MyProxy extends Proxy
    131 {
    132 flash_proxy override function callProperty(name:*,...rest):*
    133 {
    134 }
    135 flash_proxy override function getProperty(name:*):*
    136 {
    137 }
    138 flash_proxy override function setProperty(name:*,...rest):*
    139 {
    140 }
    141 }

    摘录自adobe max上的演讲稿【As3 secrets】

    人和人不要比。自己做自己。
  • 相关阅读:
    C# 备份、还原、拷贝远程文件夹
    C#SpinWait和volatile一点温习
    Asp.net Core中使用Redis 来保存Session, 读取配置文件
    C# Round源码
    C# CRC16 和汉明重量
    .net源码调试 http://referencesource.microsoft.com/
    Session.Abandon和Session.Clear的实现和区别
    log4Net 高性能写入和CSV格式
    asp.net 简单记录请求的客户端和服务端 处理时间
    asp.net 用JWT来实现token以此取代Session
  • 原文地址:https://www.cnblogs.com/crkay/p/2207232.html
Copyright © 2020-2023  润新知