Solved

Using gotoAndStop(); on movie clip?

Posted on 2004-04-14
4
1,156 Views
Last Modified: 2006-11-17
I would like to make a button with a regular movie clip. I dont want to use a button.
When I use the code nothing happens. Is it possible to use a movie clip and not a button?

on (release) {
    gotoAndStop(20);
}
0
Comment
Question by:Tobbe070599
  • 3
4 Comments
 

Author Comment

by:Tobbe070599
ID: 10826577
Is this the case in FlashMX too?:

---------------------------------------------------------------------------

In your work on Assignment 3, some of you have made the unhappy discovery that the goto and gotoAndPlay statements do not work when they are used in scripts attached to Movie Clips.

The problem arises from a serious flaw in ActionScript--which I hope will be corrected in the next version of Flash. Here's the trouble in a nutshell: As James L. Mohler notes in Flash 5: Graphics, Animation, and Interactivity, "the Go To action is limited to jumping to frames and scenes in the current movie." Or, he might have added, the current Movie Clip. Because a Movie Clip has its own timeline, the statement

gotoAndPlay("Scene 2", 1)
refers not to Scene 2 of the main movie but to Scene 2 of the Movie Clip's own timeline. If the movie clip in question does not have a second scene (and very few do), then the statement simply does nothing. You won't even see an error message, which is quite annoying.

Now here's the worst part. Since Flash wants to be an object-oriented scripting environment, you might expect to be able to direct a goto action to an appropriate target in the object hierarchy, such as the main movie. But this is impossible, because the goto action cannot refer outside the object that contains it. In short: bad software engineering.


Two Solutions
If you can substitute a button for your Movie Clip, then do so. The goto action works properly in button scripts, for some rather arbitrary reason.

In some cases you will not be able to use a button to control a transition from one movie timeline to another. For example, you may want the symbol in question to be made visible or invisible when an action is performed on another symbol. Interactions of this sort require the symbol that is being operated upon to have an instance name. Only Movie Clips can be named; buttons cannot.

Luckily, the loadMovie action lets you achieve virtually the same effect as the goto action, though in a somewhat different fashion--and loadMovie works with Movie Clips.

Unlike goto, loadMovie requires you to create a second Shockwave movie file (.swf) to hold the content you would have placed in a second scene within the main movie if you were going to rely only on buttons and goto. Setting up a second movie is a simple matter. Just copy all the frames in your second scene, select File>New, and paste those frames into the new movie. Export the .swf of your new movie under some recognizable name (e.g., "yourLastName.assn3.part2.swf"). Return to the first movie and insert the following script on the instance of your Movie Clip:

  onClipEvent("mouseUp"){
    loadMovie("yourLastName.assn3.part2.swf", 0);
  }

Your Movie Clip should now control a transition to the second part of your content--though note you are in a separate movie, so any transitions back to your main movie must also use loadMovie.

To see this technique in action, see this simple demo. The source and object files for this demo are available on Crow in multimediaShare/goToAndMovieClips/.

Observation
Macromedia is pushing out Flash versions far too quickly. In this case, they've allowed a serious inconsistency within ActionScript: you do one thing for buttons and another for Movie Clips (which were not scriptable in Flash 4). Brace yourselves, folks--messy design like this makes learning the scripting language a lot harder than it needs to be.

-----------------------------------------


0
 
LVL 1

Accepted Solution

by:
andylaw78 earned 240 total points
ID: 10827192
the code should work if you write _parent.gotoAndStop(20);
your code at the moment tells the button movieclip to go to frame 20, _parent brings it back to the main stage. hope this works! good luck
0
 

Author Comment

by:Tobbe070599
ID: 10830688
Ok, it worked but I got the problem that I would like it to jump to a specific scene.
_parent.gotoAndStop("scene2",20) this does not work, is there a way to do this?

When I use _parent it jumps to the first scene in the movie.
0
 

Author Comment

by:Tobbe070599
ID: 10830844
Thank you for your help. I gave me more info so I could solve my problem...

I found the solution here.

http://iat.ubalt.edu/courses/old/pbds668.185_Sp02/gotoProblem.shtml

Thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

760 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

20 Experts available now in Live!

Get 1:1 Help Now