as3.0怎么使用键盘控制影片剪辑的播放和帧跳转
2个回答
展开全部
空格键控制播暂停 左右键跳帧 ctrl+左右键快速跳帧
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp_func)
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown_func);
var isPlay:Boolean = true;
var _speed:uint = 0;
function onKeyUp_func(_evt:KeyboardEvent):void{
switch(_evt.keyCode){
case 32:
//空格
isPlay = !isPlay;
isPlay ? mc.play() : mc.stop();
break;
case 37:
case 39:
_speed = 0;
stage.removeEventListener(Event.ENTER_FRAME, gogogo);
mc.play();
isPlay = true;
break;
}
}
function onKeyDown_func(_evt:KeyboardEvent):void{
var _ctrlkey:int = 0;
switch(_evt.keyCode){
case 37:
if(_evt.ctrlKey) _ctrlkey = -7
_speed = _ctrlkey - 2;
stage.addEventListener(Event.ENTER_FRAME, gogogo);
break;
case 39:
if(_evt.ctrlKey) _ctrlkey = 7
_speed = _ctrlkey + 2;
stage.addEventListener(Event.ENTER_FRAME, gogogo);
break;
}
}
function gogogo(_evt:Event):void{
var _frame:uint = mc.currentFrame + _speed;
_frame = _frame < 1 ? mc.totalFrames + (_frame - 1) : _frame;
_frame = _frame > mc.totalFrames ? _frame - mc.totalFrames : _frame;
mc.gotoAndStop(_frame)
}
追问
好像有点多了。。。。能不能帮我//解释一下那个是播放那个是跳帧么。。。。。感激不尽
追答
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp_func)
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown_func);
var isPlay:Boolean = true;
var _speed:uint = 0;
//按键弹起事件
function onKeyUp_func(_evt:KeyboardEvent):void{
switch(_evt.keyCode){
case 32:
//空格
isPlay = !isPlay;
isPlay ? mc.play() : mc.stop(); //播放或暂停
//空格键按下时暂停/播放
break;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询