flex---基础
internal function init():void{ var num:int =0; var i:int = 0; do{ num = num+i; i++; }while(i<100); trace(num); txt.text = text.text+'\n'+num.toString(); var student:Object = new Object(); student.name = '小王'; student.age = 20; student.type = '本科'; for(var prop:String in student){ txt.text = txt.text + "\n"+prop+":"+student[prop].toString(); } for each(var value:* in student){ txt.text = txt.text + "\n"+value.toString(); }}internal function initApp():void{ var arr:Array = new Array(); //给数组添加元素 for(var i:Number = 0;i<6;i++){ arr.push }}outerLoop: for(var i:int=0;i<10;i++){for(var j:int=0;j<10;j++){if((j==8)&&(j==0)){ break outerLoop; //跳出标签标记的循环}trace(10*i+j);}}function sum(a:Number,b:Number,c:Number):Number{ return (a+b+c);}等价代码:var flag:Boolean = true;var flag:Boolean = new Boolean(true);var flag:Boolean = Boolean(true);var s:String = undefined; //将字符串变量设置成为undefined时,Adobe flash player会将undefined强行转换成nulluint ---正数public const PI:Number = 3.14.5926;数组:var tempArr:Array = new Array();tempArr.push("I "); //从上面放 ItempArr.unshift("love "); //从下面放元素 love I,第0个数组元素love,第一个数组元素是ItempArr.splice(1,0,"Flex3 ");//第一个参数表示放在哪里,第二个参数表示删除几个,love Flex3 Ilist1.dataProvider=tempArr; //这个list1是一个mx:List的idvar books:Array = new Array("IBM","APPLE","ORACLE","ADOBE");books.pop(); //"IBM","APPLE","ORACLE"books.shift(); //"APPLE","ORACLE"books.splice(1,1,"hehe","xixi");//"APPLE" ,"hehe","xixi"list2.dataProvider = books;var nums:Array = new Array(12,1,2,13);nums.sort(Array.NUMERIC | Array.dESCENDING); //先按照数字排序,然后按照降序排序list1.dataProvider = nums; //注意,list1有动态感知的功能,当数字被取走,list1中的东西会变化的哈nums.reverse(); //逆序list1.dataProvider = nums;var students:Array = new Array();students.push({name:"jake",age:20});students.push({name:"Tom",age:12});students.push({name:"Will",age:17});students.sortOn("age",Array.NUMERIC); //因为有多个属性,所以我们要告诉他用什么来排序var data:Array = new Array();for(var i:int =0;i<students.length;i++){ data.push(students[i].name+":"+students[i].age);}list2.dataProvider = data; //list是用一维数组做数据源的,所以上面把二维数组的东西又放到了一维数组里面了str.indexOf("w",8);//意思是从第8个位置开始往后搜索str.split(",",1);//以","分割,然后返回第一个元素,相当于str.split(",")[0]在混合运算的时候Boolean可以依照其他的运算来变化var bool:Boolean = false;bool+" aaa" //"false aaa"bool+10 //10 ,因为bool的false代表0,true代表1Boolean(10) ; //true ,只要不是0就是true,比如Boolean("0");因为不是数字0,所以转换成trueint("aa"); //0,只要不是数字字符串,都转换成0 ,int("111")转换成111try{}catch(err:Error){ trace(err.message);}obj as Canvas //相当于java中的(Canvas)objtypeof(arr) // 相当于js 中的typeof arrarr is Array //相当于java中的arr instance of Array-------------------事件-----------------------------------------事件:button.addEventListener(MouseEvent.CLICK,onClick);button.addEventListener(MouseEvent.MOUSE_OVER,onMover);internal function onClick(evt:MouseEvent):void{ txt.text = "click a button";}事件机制类继承图Object-->EventDispatcher--->DisplayObjectDisplayObject--->AVMiMovie(对as2里面的一些东西进行处理) --->Bitmap --->InteractiveObject(与事件关系最紧密) --->MorohShape(可变形的图像类) --->Shape(普通图像类) --->StaticText --->VideoInteractiveObject--->DisplayObjectContainer --->Loader --->Sprite --->MovieClip(电影片段剪辑类) --->Stage --->SimpleButton --->TextField事件捕捉,然后事件冒泡,事件发生后,每个节点可以有两次响应事件(2选1),默认关闭捕获事件internal function onPress(evt:MouseEvent):void{ //evt.stopImmediatePropagation();//这个函数相当于使得事件实效 debug('是否冒泡:'+evt.bubbles); debug('目标对象:'+evt.target); debug('所处阶段:'+evt.eventPhase); debug('当前对象:'+evt.currentTarget);}cav1.addEventListener(MouseEvent.CLICK,onPress,true);//true代表关闭冒泡,开启捕捉btn2.addEventListener(MouseEvent.CLICK,oncK1,false,5)btn2.addEventListener(MouseEvent.CLICK,oncK2,false,6)同一个按钮btn2添加了两个事件,6比5先执行