Solved

I NEED TO INPROVE THE CODE ON A MOVIECLIP, TO CONTROL ITS PLAYING SPEED!!

Posted on 2006-11-10
2
154 Views
Last Modified: 2012-05-05
Hi!

I am using this code on a movieClip to make it go from a certain frame to another (backwards or forward) depending on a global variable value. I set the global variable value by pressing buttons.
It works great!

Now: I need to control the playing speed of the movieClip, just by changing a value number directly on the code.
I believe that a 'setInterval' will work, but I don't know exactly where or how.

Can you help me?

Thanks!
Alejandro


CODE:
=============================
// This one goes on the root frame 1. It sets the global variable.
_global.destframe=1

//This one goes on the movieClip that plays backwards or forward, depending on the global variable value.
onClipEvent (enterFrame) {
      if (this._currentframe<_global.destframe) {
            this.nextFrame();
      } else if (this._currentframe>_global.destframe) {
            this.prevFrame();
      }
}
==============================
0
Comment
Question by:alexnexus
2 Comments
 
LVL 5

Accepted Solution

by:
blockage1 earned 500 total points
Comment Utility
You can use setInterval but you don't need to - in fact its better not to as setIntervals can easily get out sync with the frame update.

I'd also move your destframe property out of the global scope - otherwise you'll only ever be able to control one movieclip.

A simple solution might look like this...

CODE:
=============================
// this goes on the first frame of the movieclip
destframe = 1;
speed = 1; // higher = faster, lower = slower
frameNumber = 1;

function onEnterFrame () :Void
{
     if (_currentframe < destframe) {
          frameNumber += speed;
     } else if (_currentframe > destframe) {
          frameNumber -= speed;
     }
  trace( frameNumber );
     gotoAndStop( Math.round( frameNumber ) );
}
=============================

0
 

Author Comment

by:alexnexus
Comment Utility
Thanks!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now