Groups | Blog | Home
all groups > flash actionscript > february 2004 >

flash actionscript : how to tell what frame a movie clip is on?


VoightKampf
2/21/2004 11:50:10 PM
I've got a movie clip on the main timeline.
The movie clip contains several small animations to be used in the background
as transitions
when a button (1 of 8) is pressed.

The animations themselves are simple, 10 frame things that:

move from left to right and fade up, stop (with stop() on frame),
and then move right slightly and fade out.


I've put test buttons on the main timeline, and they all work well. Well, at
least they all
go to the frame they're supposed to, and they all move, fade up, and stop
correctly.

If I click another button, takes me to the next transition and so on...

Nice, but...

I'd like it to be a bit more slick.

What I'd like it to do is:

when button is on main is clicked, I'd like the transitions to move in and
fade up as they
do already, and stop, as they do now.

Then, when another button is clicked, I'd like the second part of their
animations to play
(the move right and fade out), BEFORE moving on to the next transition.

Life would be simple if I knew people were going to press the buttons in the
same order
every time, but...


What I've been trying to figure out is this:

How do I tell the buttons (1-8) on the main timeline WHAT FRAME my movie clip
that's sitting
on the main timeline is on, so the movie clip knows to play the ending frames
of the transition
they're currently parked in the middle of before moving to whatever frame
label has been
activated by a button.

Or, I could say it this way:


main timeline button script in goofspeak:

on (release){

tell my movie clip to play the fade out frames from the frame where it's
currently parked
before it goes to where I've asked it to go.

}


I've tried doing this every way I could think of, but I'm new to actionscript.
Instead of putting a bullet through my head, I thought I might ask for help
first...


Thanks!
abeall
2/22/2004 12:30:04 AM
Is this sort of what you're talking about?
http://www.media.heraldic.us/flashfiles/goto.swf
(test project)

If so you can look at the source:
http://www.media.heraldic.us/flashfiles/goto.fla

But Basically all that it is is you have a variable:
var destination

The when you click a button:
on(release){
play();//play the outro sequence
destination="frameLabelOfChoice";
}

Then at the end of each outro sequence:
gotoAndPlay(destination);

HTH
VoightKampf
2/22/2004 3:37:19 AM
Thanks for such a quick reply!
Yes, this looks like exactly what I'm talking about - I'm glad someone could
make sense of my ramblings.
I downloaded your fla and I'm going to take a look at it right now.

Again,
Many Thanks
VoightKampf
2/22/2004 5:46:07 AM
Okay, tried your suggestion - I must be doing something hideously stupid (not
surprising for me)

I looked at your sample and code - that's exactly what I'm trying to do. So,
since your clips right on the main timeline and mine are in a movie clip on the
main timeline, I changed the code a bit to reflect that. First, I created a
variable on the main timeline-1st frame, called var destination . From what I
gather, by doing so I'm creating a global variable that's accessible to
everything. transitions_mc is the name of my movie clip with the animations.
Here's what I did for the buttons:

on (release) {
_root.transitions_mc.play()
destination = _root.transitions_mc = "techSlide";
trace (destination);
}

I've got four test buttons set this way, with different label targets.
When I publish and test, the output window gives me what I'd expect to see.
It shows that yes, the buttons do change the var destination as it should.

So in the output window I get back:

techSlide
castSlide
filmSlide
soundTrackSlide

whenever I press the corresponding buttons.

In my movie clip,
my animations were already set up almost identically to yours in your sample,
so not much fiddling there.
At the end of each animation I have in a frame script the following:

stop();
gotoAndPlay(destination);

Now, for some reason I can't fathom, the first transition will work (fade in
and stop), but that's it.
None of the others will work.

In your code, you've phrased it:
stop();
_root.gotoAndPlay(togo);

I assume (togo) is the name of your variable?
But I didn't see where you declared it in the first place, so I must be
missing something.
Please forgive me for being long-winded, I'm really new at this...

Thanks!



abeall
2/22/2004 1:32:57 PM
Well, where you define var destination/togo isn't actaully too important,
because of how AS works the first time you assign it a value, it gets defined.
In otherwords, you don't need to define var destination really. In fact, now
that I think about it, it's actually a string anyways.

Where did you say you're buttons were? Where they are affects references, but
I think you have it right. However, this:
destination = _root.transitions_mc = "techSlide";
should be changed to:
destination = "techSlide";

Also try changing:
gotoAndPlay(destination);
to:
this.gotoAndPlay(_root.destination);//for some reason, this sometimes seems to
fix things with gotoAndPlay, and I'm sure you need the _root, since destination
is on your _root timeline. Actually you could(should) use _parent instead.

Make those little changes and see what happens.

cheers!
VoightKampf
2/22/2004 4:47:01 PM
Beally,

It doesn't look like my previous reply made it to the board...
So real quick, what you've suggested DOES work in my FlashMX version of the
file, kind of, with unpredictable results.
As a test I saved the file in Flash 5 version, and with a little tweaking, it
WORKS PERFECTLY in 5.
So now I'm going back to MX to see if I can't figure this out. I'll let you
know what happens!

Thanks Again,
-Voight-
VoightKampf
2/22/2004 5:10:23 PM
Beally-

I went into my FlashMX file and made a simple movie clip to serve as my
buttons instead of the stock -pushbutton- that's provided in components, and
everything works beautifully! Thank you, I owe you big time.
So I'm SUSPECTING that I should probably RTFM and find out what the pushbutton
component is really for.
That's what I get for taking a shortcut!
AddThis Social Bookmark Button