Actionscript(AS)
在Flash中可以在1、关键帧 2、按钮 3、动画剪辑(MC=Movie Clip)中加入AS脚本语言
A、按钮角色的指令
选择按钮角色,然后按下F9加入指令,on()
press 按着左键不放
release click
release outside 按着左键,然后拖曳鼠标离开按钮,再放开左键。
roll over 光标移动到角色上
roll out 移走
drag over 鼠标拖曳到角色上
drag out 按着拖曳离开
keypress 键盘控制
on(release){
clip.beginFill(0xFF0000);
clip.moveTo(50,50);
clip.lineTo(100,50);
clip.lineTo(100,100);
clip.lineTo(50,100);
clip.lineTo(50,50);
clip.endFill();
}
on(release){
for(var i=0;i<9;i++){
clip.lineStyle(i+1,0x66CCFF,100-i*10);
clip.moveTo(40,i*10);
clip.lineTo(120,i*10);
}
}
on(release){
setproperty("clip",_visible,false);
}
on(keyPress "<PageUp>"){
clip1._rotation+=60;
}
on(release){
fscommand("fullscreen",true);
}
on(release){
fscommand("quit");
B、动画脚色指令
首先必须给动画脚色命名,然后选取动画角色,再加入指令
onclipevent()
load/enterframe/unload/mousedown/mouseup/mousemove/keydown/keyup/data
onClipEvent(enterFrame){
if(Key.isDown(Key.DOWN)){
_root.clip._y=_y+15;
}
if(Key.isDown(Key.UP)){
_root.clip._y=_y-15;
}
if(Key.isDown(Key.RIGHT)){
_root.clip._x=_x+15;
}
if(Key.isDown(Key.LEFT)){
_root.clip._x=_x-15;
}
}
onClipEvent(mousedown){
stop();
}
onClipEvent(mouseup){
play();
}
C、关键帧指令
选取该帧,然后按下F9,输入指令
myListener=new Object();
myListener.onKeyDown=function(){
myVar=Key.isDown(Key.CAPSLOCK);
};
Key.addListener (myListener);
b1.onRelease=function(){
if(myVar){
_root.clip1._alpha=_root.clip1._alpha-20;
}
};
//Key.addListener();
//Key.getAscii ();
//Key.getCode();
//Key.isDown((Key.DOWN)
///Key.isToggled(Key.CAPSLOCK)
//Key.isDown(Key.BACKSPACE)
//Key.isDown(Key.CAPSLOCK)
//Key.isDown(Key.CONTROL)
//Key.isDown(Key.DELETEKEY)
//Key.isDown(Key.DOWN)
//Key.isDown(Key.END)
//Key.isDown(Key.ENTER)
//Key.isDown(Key.ESCAPE)
//Key.isDown(Key.INSERT)
//Key.isDown(Key.LEFT)
//Key.isDown(Key.PGDN)
//Key.isDown(Key.PGUP)
//Key.isDown(Key.RIGHT)
//Key.isDown(Key.SHIFT)
//Key.isDown(Key.SPACE)
//Key.isDown(Key.TAB)
//Key.isDown(Key.UP)
//先按键盘一键,然后点击按钮!
跟随鼠标小球
x=clip._x;
y=clip._y;
clip.onPress=function(){
clip._width=100;
clip._height=100;
clip._x=x;
clip._y=y
};
clip.onMouseMove=function(){
clip._x=_root._xmouse;
clip._y=_root._ymouse;
};
//最后的分号可以加上也可以不加上!
clip.onMouseDown=function(){
myobj=new Color(clip);
clip._height=150;
clip._alpha=50;
myobj.setRGB(0xFF0000);
};
myObject=new Object();
a=clip1._x;
b=clip1._y;
myObject.onMouseDown=function(){
clip1._x=_root._xmouse;
clip1._y=_root._ymouse;
};
myObject.onMouseUp=function(){
clip1._x=a;
clip1._y=b;
};
Mouse.addListener (myObject);
按钮鼠标变小
clip.onKeyDown=function(){
if(Key.isDown(Key.ENTER)){
clip._width=clip._width*0.8;
clip._height=clip._height*0.8;
}
};
Key.addListener(clip);
//必须要加上Key.addListener(clip)
//如果是鼠标事件则可以不上!
点击鼠标跟随
myObject=new Object();
myObject.onMouseDown=function(){
clip1._x=_root._xmouse;
clip1._y=_root._ymouse;
};
Mouse.addListener (myObject);
myListener=new Object();
myListener.onKeyDown=function(){
a=Key.getCode();
t1=a; //t1动态文本框
};
Key.addListener(myListener);
myListener=new Object();
myListener.onKeyDown=function(){
a=Key.getAscii();
t1=a;
};
Key.addListener(myListener);
button.onRelease=function(){ //button按钮名称
i=75-Math.random()*150;
j=75-Math.random()*150;
clip.beginFill(0xFF0000,60);
clip.moveTo(i,j);
clip.lineTo(i+30,j);
clip.lineTo(i+30,j+30);
clip.lineTo(i,j+30);
clip.lineTo(i,j);
clip.endFill();
};
Mouse.hide();
myObject=new Object();
myObject.onKeyDown=function(){
if(Key.isDown(Key.ENTER)){
Mouse.show();
t1="显示鼠标光标" //t1动态文本框
}
};
Key.addListener (myObject);
Stage.showMenu=false;
mySound=new Sound();
mySound.loadSound("东南西北风.mp3");
var myLength=mySound.duration;
button.onRelease=function(){ //button按钮名
mySound.start();
}
intervalID=setInterval(myfun,100);
function myfun(){
myCurlen=mySound.position;
progressbar._width=myCurlen/myLength*100;//progressbar动画剪辑名
updateAfterEvent();
}
fscommand("showmenu",false);