我有一个滑块(和按钮)的代码,它可以擦除/控制一个动画片段的时间轴,但我对于如何将它转换为动作脚本3感到迷茫。 任何帮助,将不胜感激。或者,有人知道这个功能的一个例子吗?
这是代码:
controller = this;
startR = timeline._x;
endR = startR + timeline._width;
Range = endR-startR;
playSpeed = 0;
slider.onPress = function(){
var offset = this._x - this._parent._xmouse;
this.onMouseMove = function(){
this._x = Math.min(Math.max(startR, this._parent._xmouse + offset), endR);
var percent = (this._x-startR)/Range;
target.gotoAndStop(Math.floor(percent*target._totalframes)+1)
updateAfterEvent();
}
this.onMouseMove();
}
slider.onRelease = slider.onReleaseOutside = function(){
delete this.onMouseMove;
if (playSpeed == 1) target.play()
}
this.onEnterFrame = function(){
if (!slider.onMouseMove){
if (playSpeed != 1) target.gotoAndPLay(Math.round(target._currentframe+playSpeed));
// playSpeed of 1 is handled with play() so that synced audio can play
if (target._currentframe == target._totalframes) playSpeed = 0;
var percent = (target._currentframe-1)/(target._totalframes-1);
slider._x = startR + Range*percent;
}
}
// Buttons
start_btn.onRelease = function(){
playSpeed = 0;
target.gotoAndStop(1);
}
rw_btn.onPress = function(){
this.orig = playSpeed;
playSpeed = -2;
}
rw_btn.onRelease = rw_btn.onReleaseOutside = function(){
playSpeed = this.orig;
if (playSpeed == 1) target.play();
}
stop_btn.onRelease = function(){
playSpeed = -1;
}
play_btn.onRelease = function(){
playSpeed = 1;
target.play();
}
ff_btn.onPress = function(){
this.orig = playSpeed;
playSpeed = 2;
}
ff_btn.onRelease = rw_btn.onReleaseOutside = function(){
playSpeed = this.orig;
if (playSpeed == 1) target.play();
}
end_btn.onRelease = function(){
playSpeed = 0;
target.gotoAndStop(target._totalframes);
}
如果这对于某人在业余时间这样做很复杂, 也许有人有兴趣在as3中为我创建这个功能,当然付费?
提前谢谢, 符号答案 0 :(得分:0)
下面是一个使用滑块的例子
var mySlider:Slider;// slider on timeline
mySlider.liveDragging=true;
mySlider.addEventListener(Event.CHANGE, handlerScrollEvent);
function handlerSliderChange(event:ScrollEvent):void{
var value:Number = (event.target as Slider).value;
// TODO convert value from 0-10 to number of frames based on percentage
}
答案 1 :(得分:0)
这也是一团糟,但我猜你不管怎样都不需要它。
MovieClip具有实例名称剪辑。
Slider(它位于“组件”菜单中)具有实例名称滑块和属性 最大值为100。
6个按钮的实例名称为playBtn,stopBtn,reverseBtn,fasterBtn,slowBtn 他们做了名字所暗示的^^。
将此作为框架脚本使用:
import fl.events.*;
import fl.controls.*;
clip.stop();
//slider
var slider:Slider;
slider.liveDragging=true;
slider.addEventListener(SliderEvent.CHANGE, sliderListener);
slider.addEventListener(SliderEvent.THUMB_PRESS, stopListener);
slider.addEventListener(SliderEvent.THUMB_RELEASE, playListener);
//update thumb
clip.addEventListener(Event.ENTER_FRAME, enterFrameListener);
//buttons
playBtn.addEventListener(MouseEvent.CLICK,playListener);
stopBtn.addEventListener(MouseEvent.CLICK,stopListener);
reverseBtn.addEventListener(MouseEvent.CLICK,reverseListener);
fasterBtn.addEventListener(MouseEvent.CLICK,faster);
slowerBtn.addEventListener(MouseEvent.CLICK,slower);
var speed:int=1;
var lastSpeed:int=1;
//when slider value changes
function sliderListener(event:SliderEvent):void{
var frame:Number = Math.round(clip.totalFrames*event.value/100);
clip.gotoAndStop(frame);
}
function playListener(event:Event){speed=lastSpeed} //playBtn or release Thumb
function stopListener(event:Event){lastSpeed=speed;speed=0}//stopBtn or press Thumb
function reverseListener(event:Event){speed*=-1}//reverseBtn
function faster(event:Event){speed++}//fasterBtn
function slower(event:Event){speed--}//slowerBtn
function enterFrameListener(event:Event){
if(speed!=0){
if(clip.currentFrame+speed<1){
clip.gotoAndStop(clip.totalFrames+speed+1);
}else if(clip.currentFrame+speed>clip.totalFrames){
clip.gotoAndStop(0+speed);
}else{
clip.gotoAndStop(clip.currentFrame+speed);
}
slider.value=Math.round(clip.currentFrame/clip.totalFrames*100);
}
}
正如我刚看到你的as2脚本有一个快进。所以这里将是ffBtn的附加脚本:
ffBtn.addEventListener(MouseEvent.MOUSE_DOWN,ffStartListener);
ffBtn.addEventListener(MouseEvent.MOUSE_UP,ffEndListener);
ffBtn.addEventListener(MouseEvent.MOUSE_OUT,ffEndListener);
var ff:Boolean=false;
function ffStartListener(event:Event){ff=true;speed*=2};
function ffEndListener(event:Event){
if(ff){
speed/=2;
ff=false;
}
}
请参阅此处的.swf:http://swftly.com/slider