flash action实例学习笔记.docx
《flash action实例学习笔记.docx》由会员分享,可在线阅读,更多相关《flash action实例学习笔记.docx(16页珍藏版)》请在冰点文库上搜索。
![flash action实例学习笔记.docx](https://file1.bingdoc.com/fileroot1/2023-7/2/f3296111-7154-4dcb-82f1-83ae90d3aebb/f3296111-7154-4dcb-82f1-83ae90d3aebb1.gif)
flashaction实例学习笔记
css属性:
动作脚本属性:
是在flash内部创建的样式表属性
textAlign
fontSize
textDecoration
marginLeft
marginRight
fontWeight
fontStyle
textindent
fontFamily
color
display
定义的外部css属性需要加上-号
例如:
text-alignalign的a不需要大写
实例:
mycar.play()播放电影剪辑 _width宽度、
事件处理函数:
对事件作出响应的程序段
on(realse){//单击按钮时播放动画
play();
}
_x_y_alpha横坐标纵坐标透明度
Date.getHours()
Math.abs() 常数Math.PI
常数:
Key.HOMEKey.CONTROL Key.ENTER分别表示home,ctrl键enter键
Ationscript的关键字
Breakcaseclasscontinuedefaultdelete
Ifimplementsimportininstanceofinterface
Dynamicelseextendsforfunctionget
Intrinsicnewprivatepublicreturnset
Staticswitchthistypeofvarvoid
Whilewith
\f换页符
\n换行符
\r回车符
vara=99;
varb=88;
If(a>b){
trace(“a>b”);
}elseif{
trace(“a
}
计算绝对值
varx=Math.abs(“-4”);
影片剪)
myMovieClip.startDrag(true)将影片剪辑设置为可拖动
myMovieClip._x可获取横坐标属性值
TextFiled.StyleSheet类
getStyle()
getStyleNames()
load()
parseCSS()
setStyle()
gotoAndStop
gotoAndPlay(9);
gotoAndPlay(“scene2”,2)
场景2的第二帧
nextFrameprevFrame
nextSceneprevScene
按钮对事件作出的反应
press
release
rollOver
rollOut
dragOver
dragOut
keyPress(“key”)
on(release,keyPress“”){
_root.car.gotoAndPlay(12);
_root.bus.nextFrame();
car._x+=5;
}
for(varIin_root){
_root[i]._rotation+=35;
}
指路行驶:
on(keyPress""){
car._x-=5;
}
on(keyPress""){
car._x+=5;
}
on(keyPress""){
car._y-=5;
}
on(keyPress""){
car._y+=5;
}
还可加入方向car.rotation-=90;
小球回旋影片剪辑
onClipEvent(load){
varwidth=_root._width;
varheight=_root._height;
vardeltaX=deltaY=10;
_x=_root._width/100;
_y=_root._height/100;
}
onClipEvent(enterFrame){
_x+=deltaX;
_y+=deltaY;
if(_x>=width-10||_x<=10){
deltaX*=-1;
}
if(_y>=height-10||_y<=10){
deltaY*=-1;
}
}
影片剪辑事件;
load
unload
enterFrame
mouseMove
mouseDown
mouseUp
keyDown
keyUp
data
星星下落程序自定义事件处理函数
stop();
varflag=1;
_root.onMouseDown=function(){
flag*=-1;
};
for(variin_root){
_root[i].onEnterFrame=function(){
if(flag==1){
this._y+=10;
this._alpha-=2;
this._xscale=this._yscale-=1;//_xscale横坐标缩放if(this._y>=430){
this._y=-30;
this._xscale=this._yscale=this._alpha=100;
}
}
};
}
鼠标右键错误:
varmy_cm=newContextMenu();
my_cm.customItems.push(newContextMenuItem()("旋转",rotate));
my_cm.customItems.push(newContextMenuItem()("下落",drop));
my_cm.customItems.push(newContextMenuItem()("缩放",zoom));
my_cm.hideBuiltInItems();
functionrotate(obj,item){
obj.onEnterFrame=function(){
this._rotation+=15;
};
}
functiondrop(obj,item){
obj.onEnterFrame=function(){
this._y=(this._y+8)%400;
};
}
functionzoom(obj,item){
obj.onEnterFrame=function(){
this._xscale=this._yscale-=5;
if(this._xscale<=-100){
this._xscale=this._yscale=100;
}
};
}
for(variin_root){
_root[i].menu=my_cm;
}
游动的死鱼:
total=100;
varheadVel=13;
varbodyVel=1.1;
varscaleDelta=3;
varxpos=newArray();
varypos=newArray();
for(i=1;i<=total;i++){
if(i==1){
attachMovie("head","fish"+i,total+1-i);
}elseif((i==2)||(i==13)){
attachMovie("fin","fish"+i,total+1-i);
}else{
attachMovie("body","fish"+i,total+1-i);
}
with(_root["fish"+i]){
_xscale-=scaleDelta*i;
_yscale-=scaleDelta*i;
_alpha=100-(100/total)*i;
}
}
_root.onEnterFrame=function(){
xpos[0]+=(_xmouse-xpos[0])/headVel;
ypos[0]+=(_ymouse-ypos[0])/headVel;
for(i=1;i<=total;i++){
xpos[i]+=(xpos[i-1]-xpos[i])/bodyVel;
ypos[i]+=(ypos[i-1]-ypos[i])/bodyVel;
}
for(i=1;i<=total;i++){
with(_root["fish"+i]){
_x=(xpos[i-1]+xpos[i])/2;
_y=(ypos[i-1]+ypos[i])/2;
_rotation=90+180/Math.PI*Math.atan2((ypos[i]-ypos[i-1]),(xpos[i]-xpos[i-1]));
}
}
};
删除动态生成的实例;
vari=j=0;
_root.onMouseDown=function(){
attachMovie("star","star"+i,i);
_root["star"+i]._x=_xmouse;
_root["star"+i]._y=_ymouse;
i++;
};
_root.onKeyDown=function(){
if(_root["star"+j]._visible){
removeMovieClip(_root["star"+j]);
j++;
}
};
Key.addListener(_root);
深度的应用:
attchMoviegetDepthgetNextHighestDepth
getInstanceAtDepth()//返回指定深度的实例
swapDepth()
for(vari=0;i<6;i++){
attachMovie("shape","shape"+i,i);
_root["shape"+i]._x=80*i;
_root["shape"+i]._y=80*i;
_root["shape"+i].onRelease=function(){
while(this.getDepth()!
=_root.getNextHighestDepth()-1){
for(varm=this.getDepth();//当前实例深度值
m<_root.getNextHighestDepth()-1;m++){
//依次比较当前深度与最大深度,并确保当前深度为最大
_root.getInstanceAtDepth(m).swapDepths(_root.getInstanceAtDepth(m+1));
}
}
};
}
碰撞试验但不能完成所有操作:
varvel=newArray();
for(vari=0;i<3;i++){
attachMovie("ball",2*i+1,2*i+1);
attachMovie("ball",2*i,2*i);
with(_root[2*i]){
_x=_width/2;
_y=_height/2;
vel[2*i]=5+i*5;
}
_root[2*i].onEnterFrame=function(){
varid=(this._y-50)/100;
this._x+=_root.vel[2*id];
this._rotation+=360*_root.vel[2*id]/(2*Math.PI*(this._width/2));
if(this.hitTest(0,this._y,false)){
vel[2*id]*=-1;
}
};
with(_root[2*i+1]){
_x=400-_width/2;
_y=50+i*100;
vel[2*i+1]=10+i*2;
}
_root[2*i+1].onEnterFrame=function(){
varid=(this._y-50)/100;
this._x-=_root.vel[2*id+1];
this._rotation-=360*_root[2*id+1]/(2*Math.PI*(2*this._width/2));
if(this.hitTest(_root[2*id])||this.hitTest(400,this._y,false)){
vel[2*id+1]*=-1;
}
};
}
startDrag(true,left,top,right,bottom)
stopDrag()
的用法
onClipEvent(load){
x=_x;
y=_y;
}
on(press){
this.startDrag(true,x,y,x,y+300);
}
on(release,releaseOutside){
this.stopDrag();
}
动态遮罩的应用:
this.removeMovieClip()
__.setMask(---)
_root.createEmptyMovieClip("mask",1);
picture.setMask(mask);
_root.mask.onMouseMove=function(){
vari=this.getNextHighestDepth();
this.attachMovie("circle",i,i);
this[i]._x=this._xmouse;
this[i]._y=this._ymouse;
};
mc的绘图功能:
vardrag=false;
_root.createEmptyMovieClip("square",0);
with(square){
lineStyle(0,0xFF0000,100);
moveTo(-5,-5);
beginFill(0xDDDDDD);
lineTo(-5,5);
lineTo(5,5);
lineTo(5,-5);
lineTo(-5,-5);
endFill();
}
square._visible=false;
for(vari=1;i<=5;i++){
_root.square.duplicateMovieClip("square"+i,i);
_root["square"+i]._x=550*Math.random();
_root["square"+i]._y=400*Math.random();
_root["square"+i].onPress=function(){
this.startDrag(true);
drag=true;
};
_root["square"+i].onRelease=function(){
this.stopDrag();
drag=false;
drawlines();
};
}
functiondrawlines(){
for(vari=1;i<5;i++){
_root.createEmptyMovieClip("line"+i,i+5);
with(_root["line"+i]){
_x=_root["square"+5]._x;
_y=_root["square"+5]._y;
lineStyle(1,0xffff00,50);
lineTo(_root["square"+i]._x-_root["square"+5]._x,_root["square"+i]._y-_root["square"+5]._y);
}
}
}
drawlines();
_root.onMouseMove=function(){
if(drag==true){
drawlines();
}
updateAfterEvent();
};
html标签的使用
_root.createTextField("myTxt",0,50,50,400,300);
myTxt.html=true;
myTxt.text="String.fromCharCode(26*Math.random()+65)";
with(myTxt){
textColor=0xff0dbf;
backgroundColor=0xdddddd;
}
myTxt.htmlText="
";
math类的应用:
varradius=150;
varx0=300;
vary0=200;
vari=0;
varcolor0=0x885533;
_root.createEmptyMovieClip("circle",0)
with(circle){
_x=x0;
_y=y0;
moveTo(radius,0);
}
_root.circle.onEnterFrame=function(){
this.lineStyle(6,color0,100,7);
this.lineTo(radius*Math.cos(i*Math.PI/180),-radius*Math.sin(i*Math.PI/180));
i++;
if(i==360){
i=0;
color0^=0xffffff;
}
};
Math类的属性:
E
PI
SQRT2
SQRT1_2
LN2
………………
Math类的方法:
abs()
random()
round()
exp()
log()
atant2()
floor()
ceil()
pow()
sqrt()
max()
min()
sin()
cos()
tan()
acos()
acos()
atan()