Copy link to clipboard
Copied
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
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);
}
f
Copy link to clipboard
Copied
copy and paste the code suggested to control the movieclip timeline.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
i understand that. copy and paste the code that works with one movieclip.
Copy link to clipboard
Copied
I think he expects us to download the fla fron his dropbox link.
Copy link to clipboard
Copied
ok, I had tryed that and it had always given errors for duplacated functions, even after I had renamed them there were bugs so I was unsure. I had tryed other methods rather than copy and pasting and wasn't sure wich way of going about it was correct but I will now be going though the code to try and resovle the duplacaion bugs Thanks to the point in the right direction.
p.s. apologies is posting a link was presumptuous, force of habbit from uni.
Copy link to clipboard
Copied
copy the code that works for one movieclip (that i'd suggested in another thread) and paste that code into this thread. i'll then show you how to use that code with multiple movieclips.
Copy link to clipboard
Copied
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 link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
This is superb kglad.
The code not only works but for what ever reason seems to run quite a bit smother on my set up than before, less jumpy.
Although I wasnt able to manipulate the original code myself I spent alot of time trying and I feel I have learnt a huge amount about the workings of AS3 in the prosess.
Thanks for the help, really has helped my confidence in flash.
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now