·您当前的位置:首页 > 技术教程 > AS2与AS3技术 >

[AS3]AS3,其实就是这么简单(AS3学习经验)

时间:2013-02-19 00:03CuPlayer.com
[AS3]AS3,其实就是这么简单(AS3学习经验)

//flash里的对象Object
myObj=new Object();

//对象的属性
myObj.b="Hello";
trace(myObj.b);

//对象的方法
myObj.addFunc=function(a,b){
 return a+b;
}
trace(myObj.addFunc("Hi, ","Andy"));

//对象嵌套
myObj2=new Object();
myObj2.innerObj=new Object();
myObj2.innerObj.a=10;

//MovieClip的属性
_mc._x=0;
_mc._y=0;
_mc._rotation=0;
_mc._xscale=0;
_mc._yscale=0;
_mc._xmouse=0;
_mc._ymouse=0;
_mc._height=0;
_mc._width=0;
_mc._name="mc";
_mc._alpha=0;
b=_mc._currentframe; //mc内当前播放的帧的位置
b=_mc._totalframes; //mc内总的帧数

//MovieClip的方法
_mc.createEmptyMovieClip("my_mc",0); //应用于mc中的onEnterFrame方法/事件
_mc.attachMovie("linked_mc","new_mc",0); //从库中取出mc
_mc.removeMovieClip(); //删除mc,适用于运行时创建的mc,如上面的两种方法创建的mc
_mc.stop();
_mc.play();
_mc.nextFrame();
_mc.prevFrame();
_mc.gotoAndPlay(1);
_mc.gotoAndStop(1);
_mc.loadMovie(swfname);
_mc.unloadMovie(jpgormc); //清除由loadMovie填充的内容,清除后可以用removeMovieClip()删除mc
_mc.getBytesTotal(); //载入swf或jpg的总大小
_mc.getBytesLoaded(); //已经载入的大小
_mc.hitTest(x,y,shapflag); //指定的位置是否与mc接触
_mc.hitTest(anotherMc); //两mc交叠返回true
_mc.setMask(maskMC);
_mc.startDrag();
_mc.startDrag(lock,x1,x2,y1,y2);
_mc.stopDrag();
_mc.swapDepths(depth); //指定mc到深度depth
_mc.getDepth(); //获得mc的深度
_mc.getNextHighestDepth(); //返回下一个没有被使用的深度

//Movie的事件
_mc.onRelease=function(){}
_mc.onReleaseOutside=function(){}
_mc.onRollOut=function(){}
_mc.onRollOver=function(){}
_mc.onPress=function(){}
_mc.onEnterFrame=function(){}
_mc.onMouseDown=function(){}
_mc.onMouseMove=function(){}
_mc.onMouseUp=function(){}
_mc.onDragOut=function(){}
_mc.onDragOver=function(){}
_mc.onKeyDown=function(){}
_mc.onKeyUp=function(){}

//Key类
lastCode=Key.getCode();
ascii=Key.getAscii();
Key.isDown(keycode);
Key.addListener(listenerObject);
Key.removeListener(listenerObject);
capsDown=Key.isToggled(20); //or 144 专用Cap Lock键和Num Lock键

//Key类常量
Key.BACKSPACE
Key.CAPSLOCK
Key.CONTROL
Key.DELETEKEY
Key.DOWN
Key.END
Key.ENTER
Key.ESCAPE
Key.HOME
Key.INSERT
Key.LEFT
Key.PGDN
Key.PGUP
Key.RIGHT
Key.SHIFT
Key.SPACE
Key.TAB
Key.UP

//Mouse类
Mouse.hide(); //关闭鼠标指针
Mouse.show();
Mouse.addListener(listenerObject);
Mouse.removeListener(listenerObject);

//Stage类
Stage.scaleMode="showAll"; //exactFit,noBorder,noScale
Stage.align="T"; //T,B,L,R,TL,TR,BL,BR
w=Stage.width;
h=Stage.height;
Stage.addListener(listenerObject); //结合onResize()
Stage.removeListener(listenerObject);
//Stage.showMenu
this.createTextField("showMenu_txt", this.getNextHighestDepth(), 10, 10, 100, 22);
showMenu_txt.html = true;
showMenu_txt.autoSize = true;
showMenu_txt.htmlText = "Stage.showMenu = "+Stage.showMenu+"";
function toggleMenu() {
    Stage.showMenu = !Stage.showMenu;
    showMenu_txt.htmlText = "Stage.showMenu = "+Stage.showMenu+"";
}

//Math类
Math.abs();
Math.acos(); //反余弦
Math.asin(); //反正弦
Math.atan2();
Math.atan();
Math.ceil(); //向上舍入
Math.floor(); //向下舍入
Math.cos();
Math.sin();
Math.max(x,y);
Math.min(x,y);
Math.random();
Math.round(); //四舍五入
Math.sqrt();

//Array类
newArray=new Array("a","b","c","d");
newArray=oldArray.concat(item1,item2,item3); //连接数组item1..是数组
joined=newArray.join("|"); //用|连接数组元素成字符串
newArray.reverse(); //反向排序


////////////////////////////////
//用onEnterFrame时记得要delete
//举一反三:mc的所有事件用完后都要delete掉

_root.createEmptyMovieClip("new_mc",this.getNextHighestDepth());
new_mc.onEnterFrame=function(){
 this._alpha-=10;
 if(this._alpha<10){
  delete this.onEnterFrame;
  this.removeMovieClip();
 }
}

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器