Dynamically modify the playback speed of a MovieClip instance

BACKGROUND — skip past this if you just want to see my question and don’t care about the “why” :slight_smile:
Hi all. Sorry if this is similar to an already-posted question/answer — the Search function isn’t working for me (Java behaves strangely on my computer), and the stickies and tutorials I skimmed didn’t seem to have this. If there is a solution posted already, feel free to direct me to it!

Anyway. I’m totally new to ActionScript (and Flash… and programming… hush), and working on a personal project that so far has involved heavily modifying someone else’s much better coding. Mostly, I’ve been able to feel my around between playing with their code, discovering that trace() exists (boy, did that help), Google, and the Adobe Flash CS4 online documentation.

But there’s no example or template preexisting in the .fla for this step, so I’m on my own (and drowning). And I finally decided that I’m just going to have to either give up on the idea, implement a really crude and clumsy solution, or ask people who know better.

**MY QUESTION
**OK. So, it’s a little more complicated than this (lots more events going on), but for these purposes the set-up can basically be thought of like this:


DOCUMENT
30 fps. This is a 2-frame wonder with a million little
clips and buttons and stuff going on. The Stage
itself doesn't play (frame 1 and frame 2 both contain
"stop()" commands), but serves more as an
ActionScript container for the interactive stuff.

The primary code (ActionScript for stage, frame 2)
for the animation is a series of reactions to user
input which are checked and (if appropriate)
executed every 0.1 seconds through a setInterval
loop (setInterval (checker, 100)). The code in (stage,
frame 1) basically sets up and holds all the necessary
variables, as well as defining the functions that will
be called during (frame 2).

LIBRARY
1. theButton_A, a generic button
2. theButton_B, another generic button
3. theMovieClip, a 30-second long, 30-frame long MovieClip.
This is a graphic effect that represents, essentially, a
shine passing over something. It's not an animation with
a "story".

STAGE
1. theButton_A instance, "button_a"
2. theButton_B instance, "button_b"
2. theMovieClip instance, "movieclip_a"

ACTIONSCRIPT
1. "clipSpeed", a variable that changes dynamically in
reaction to other parts of the code (which don't do
anything particularly amazing except change the value
of clipSpeed to different numbers at different times)


All I want to do is the following:

  1. Click on “button_a” or “button_b”
  2. … which causes “movieclip_a” to play

But wait… it’s not quite that simple. What I really want is:

  1. Click on “button_a”
  2. … which causes “movieclip_a” to play normally
  3. Click on “button_b”
  4. … which causes “movieclip_a” to play at twice the normal speed

But wait! … it’s a little more still.

  1. Click on “button_a”
  2. … which causes “movieclip_a” to play normally
  3. Click on “button_b”
  4. … which causes some kinda code to check the value of a variable, “clipSpeed”
  5. … which then causes “movieclip_a” to play at “clipSpeed”

And I’m at a loss as to how to implement this seemingly-simple operation. Nothing I’ve tried has produced remotely correct results.

For reference, the range of playback speed for “movieclip_a” will be, dynamically, between taking 1.0 seconds to play through (the default) and 1.50 seconds to play through (the maximum speed boost). Yes, 1.0s to 1.5s … it really does matter, a lot, that this visual be the precise speed it should be.

**WHAT I HAVE TRIED
**… is probably best not mentioned in front of Flash developers, or at least ones that love their tools. But briefly:
• A bunch of trying to play with “enterFrame” events that really didn’t work but did confuse me and make me afraid of messing with the MovieClip class (and its events) ever again.
• A tutorial designed for Flash MX which caused CS4 to yell at me a lot until I politely scrapped the idea.
• Some time spent learning that if you want a variable to be global, you don’t declare it inside a button’s “onRelease” code (sigh).
• Probably other totally off-base attempts that my memory destroyed in self-defense.
• Something that sort-of worked, but gave really inconsistent results and didn’t change the speed properly:


(attached to  "movieclip_a" (the instance), which I know I
wouldn't get away with if the creator had set this as
AS3... heh)

onClipEvent (enterFrame)
{ 
          if (speedUp == true)
         { 
                  frame = (this._currentframe + clipSpeed); 
                  this.gotoAndPlay (frame);
         }
   } 

That had two problems.

  1. It totally ignored any non-integer values for “clipSpeed”

  2. I’m not comfortable putting the ActionScript in an “enterFrame” event because
    a. I don’t understand what I’m doing and
    b. I’m worried that there will be conflicts between the movie framerate (which is, I assume, also the rate at which this action is called) and the new speed we’re trying to play it at
    c. AS3-mode tells me not to in really large, flashing, angry red letters (well… it feels like it, at least).

WHAT I’M LOOKING FOR
Some explanation of where to even start would be great. I’m lost at sea with all this programming stuff, and nothing does what I expect it to do! (although Flash is probably complaining, “Nothing this user tells me is what I expect her to do!”).

If you want to just toss a chunk of shiny polished code at me, obviously, I’ll be appreciative. But if you have the time, I’d much rather be given a start and a direction and work through it myself… I’m honestly trying to learn here, as much as just make the thing work.

But, any little tidbit of help you can offer at all would be great too. Thanks! :slight_smile: