Skip to main content
Participant
April 25, 2014
Answered

Help with AS3 playback in timline

  • April 25, 2014
  • 1 reply
  • 860 views

About a week ago I was helped by the community with code that allowed me to control the timeline of a movie clip with the mouse position, this worked fantastically . The code works by having a movie clip on the stage, and the timeline within that movie clip is what is being controlled.

The problem is when I try to incorporate this over several movie clips. The code does not function, I have tired changing the necessary instance name, even some "if" statments to get the right frame on the timeline but I just do not think I have enough of a grasp of actions script to make a real go of it.

I find it quite hard to explain and so I have left a link to the flash file at the bottom of the post. The file contains the code and the bair bones set up to give good idea of what I am trying to archive (2 movie clips with timelines I want to scrub through as well as a looping background, and a shape to represent the animation and of course the code).

As you will see the first timeline works great, with the scrolling being contolled by the distance the mouse is from the center point. Once the butten is clicked to jump to the second movie clip is where i am stumped.

Thanks in advance for any help, or at least reading this far

https://www.dropbox.com/s/jfqkxlwnnapmjfl/TEST.fla

This topic has been closed for replies.
Correct answer kglad

here is the code. Base is the name of the instance of the movie clip.

var mc:MovieClip =Base; 

var maxScrollSpeed:int=100;  // max fps for mc

var m:Number;

var b:Number;

var prevFPS:int;

paramF(0,-maxScrollSpeed,stage.stageWidth,maxScrollSpeed);

this.addEventListener(MouseEvent.MOUSE_MOVE,scrollF);

function scrollF(e:Event):void{

var fps:int = Math.round(m*mouseX+b);

if(prevFPS&&prevFPS!=fps){

if(fps!=0){

if(fps>0){

playF(mc,mc.currentFrame,mc.totalFrames,fps);

} else {

playF(mc,mc.currentFrame,1,-fps);

}

} else {

stopF(mc);

}

}

prevFPS=fps;

}

function playF(mc:MovieClip, m:int, n:int, fps:int):void {

    var playFFF2:Function = function(mc:MovieClip):void {

        if (mc.m<mc.n) {

            mc.nextFrame();

        } else {

            mc.prevFrame();

        }

        if (mc.currentFrame == mc.n) {

            clearInterval(mc.int);

        }

        //updateAfterEvent();

    };

    mc.m = m;

    mc.n = n;

    mc.fps = fps;

    mc.gotoAndStop(mc.m);

    clearInterval(mc.int);

    mc.int = setInterval(playFFF2, 450/mc.fps, mc);  //manipulation area size

}

function stopF(mc:MovieClip):void {

    clearInterval(mc.int);

}

function paramF(x1:Number,y1:Number,x2:Number,y2:Number):void{

m=(y1-y2)/(x1-x2);

b=y1-m*x1;

}


copy and paste the code in the shaded area.

thereafter if you want to scroll a movieclip (eg, Base), call startscrollF and pass that movieclip:

startscrollF(Base);

if you want scrolling to stop, call stopscrollF() passing no parameters.

var mc:MovieClip

var maxScrollSpeed:int=100;  // max fps for mc

var m:Number;

var b:Number;

var prevFPS:int;

paramF(0,-maxScrollSpeed,stage.stageWidth,maxScrollSpeed);

function startscrollF(_mc:MovieClip):void{

mc=_mc;

this.addEventListener(MouseEvent.MOUSE_MOVE,scrollF);

}

function stopscrollF(_mc:MovieClip):void{

this.removeEventListener(MouseEvent.MOUSE_MOVE,scrollF);

}

function scrollF(e:Event):void{

var fps:int = Math.round(m*mouseX+b);

if(prevFPS&&prevFPS!=fps){

if(fps!=0){

if(fps>0){

playF(mc,mc.currentFrame,mc.totalFrames,fps);

} else {

playF(mc,mc.currentFrame,1,-fps);

}

} else {

stopF(mc);

}

}

prevFPS=fps;

}

function playF(mc:MovieClip, m:int, n:int, fps:int):void {

    var playFFF2:Function = function(mc:MovieClip):void {

        if (mc.m<mc.n) {

            mc.nextFrame();

        } else {

            mc.prevFrame();

        }

        if (mc.currentFrame == mc.n) {

            clearInterval(mc.int);

        }

        //updateAfterEvent();

    };

    mc.m = m;

    mc.n = n;

    mc.fps = fps;

    mc.gotoAndStop(mc.m);

    clearInterval(mc.int);

    mc.int = setInterval(playFFF2, 450/mc.fps, mc);  //manipulation area size

}

function stopF(mc:MovieClip):void {

    clearInterval(mc.int);

}

function paramF(x1:Number,y1:Number,x2:Number,y2:Number):void{

m=(y1-y2)/(x1-x2);

b=y1-m*x1;

}

1 reply

kglad
Community Expert
Community Expert
April 26, 2014

copy and paste the code suggested to control the movieclip timeline.

Kyle1992Author
Participant
April 26, 2014

That does work it works very well in fact.

But the problem I am encountering is when I have the code work on one movie clip, and then cannot get it to work on a second clip later on in the main timeline.

kglad
Community Expert
Community Expert
April 26, 2014

i understand that.  copy and paste the code that works with one movieclip.