Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2006-11-10
2
Medium Priority
?
162 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 2000 total points
ID: 17918960
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
ID: 17940423
Thanks!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

927 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