Solved

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

Posted on 2006-11-10
2
155 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
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 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.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

863 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

25 Experts available now in Live!

Get 1:1 Help Now