0
votes

i have this code for a slider (and buttons) which scrubs/controls the timeline of a movieclip, but i am lost as to how to convert it to actionscript 3. any help would be appreciated. alternatively, does someone know of an as3 example of this functionality?

here is the code:

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);
}

if this is way to complicated for someone to do it in his spare time, maybe someone is interested in creating this functionality for me in as3, paid of course?

thanks in advance, semiotic

2
you're better off creating one from scratch rather than trying to convert this mess - Ronnie

2 Answers

0
votes

heres an example to use the slider

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
}
0
votes

It's kind of a mess aswell but I guess you wont need everything of it anyways.

The MovieClip has the instance name clip.

The Slider (it's in the Components menu) has the instance name slider and in the properties a maximum value of 100.

The 6 buttons have the instance names playBtn, stopBtn, reverseBtn, fasterBtn, slowerBtn and they do what the names suggest ^^.

Use this as the frame script:

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);
    }
}

As I just saw your as2 script has a fast forward. So here would be the additional script for a 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;
    }
}

See the .swf here: http://swftly.com/slider