View Full Version : Movie clip object + gotoAndStop
thosecars82
06-12-2008, 08:02 PM
Hello there
I am stuck with a really silly example. I did this:
1. I put a Button on the stage.
2. I convert this Button into a Movie Clip.
3. I link this MovieClip to a Class like this:
import mx.controls.Button;
import mx.utils.Delegate;
class Caca{
var b1:Button;
function onLoad(){
b1.addEventListener("click", Delegate.create(this,b1_onClick));
}
public function b1_onClick()
{
b1._parent.gotoAndStop("open");
trace("HELLO");
}
}
4. I click twice inside the Movie Clip which I just created to go inside of this movie clip for the next steps.
5. I add a keyframe in the frame number 10.
6. I draw a circle on the stage inside of frame number 10 right besides the button.
7. I put "open" as the frame label for frame number 10.
8. I put stop() in the actions corresponding to frame number 1 and 10.
When I test the application, I can see the Message "HELLO", but I cannot see the circle I drew. That is to say, the gotoAndStop is not working to modify the current frame in the timeline of the movieclip as I expected. Does anyone know how to solve this?
What I do know is that if I replace b1._parent.gotoAndStop("open") with
gotoAndStop("open"), the effect is that the frame of the main timeline gets modified. Nonetheless, that is not the effect I am looking for. What I want, is changing the frame in the timeline associated with the movieclip.
Thanks in advance
Medyman
06-13-2008, 12:37 PM
I'm a little confused by your set up. How many movieclips do you have? You have a button inside of a movieclip inside of a movieclip? And b1 is the instance name of your button?
In that case b1._parent would be referring to the container movieclip. So b1._parent.gotoAndStop isn't referring to the main timeline. Try replacing b1._parent with _root. If it works, then my assumption is right and it's a path issue. In which cause, you'll want to add multiple _parent path directives to your gotoAndStop method.
If I understand your setup properly it would be b1._parent._parent._parent.gotoAndStop().
thosecars82
06-13-2008, 01:03 PM
I'm a little confused by your set up. How many movieclips do you have? You have a button inside of a movieclip inside of a movieclip? And b1 is the instance name of your button?
In that case b1._parent would be referring to the container movieclip. So b1._parent.gotoAndStop isn't referring to the main timeline. Try replacing b1._parent with _root. If it works, then my assumption is right and it's a path issue. In which cause, you'll want to add multiple _parent path directives to your gotoAndStop method.
If I understand your setup properly it would be b1._parent._parent._parent.gotoAndStop().
Now my current problem is this:
I have coded the drop down menu from
http://www.toxiclab.org/tutorial.asp?ID=47 and it works. Nonetheless, there is something that I dislike. I would like to use a movieclip to build the invisible buttons. That way, I could link the movieclip components to a movieclip class in actionscript in which I would code what currently is done like:
on (rollOver, dragOver) {
gotoAndStop("closed");
}
What happens is that I don't like to have my code scattered around components. On the other hand, as far as I know, the only components which might be linked to an actionscript class are movieclips. For example, as far as I am concerned, I cannot link a home made button component from the stage to an action script class.Please, tell me if I am wrong about this last point. If I could do that, the I wouldn't mind to use the component button to build these invisible buttons.
Thanks a lot in advance.
Medyman
06-13-2008, 01:22 PM
What happens is that I don't like to have my code scattered around components.
That's a good thing. Your code should all be in the same place. If you're doing OOP, then in the same class per object.
On the other hand, as far as I know, the only components which might be linked to an actionscript class are movieclips. For example, as far as I am concerned, I cannot link a home made button component from the stage to an action script class.Please, tell me if I am wrong about this last point. If I could do that, the I wouldn't mind to use the component button to build these invisible buttons.
Well there is no such thing as a home-made component, really. At least not in the sense that you're talking about. Plus what you're using is not the button component (that's a totally different thing). You're using a button object.
If you don't like the behavior of the button object, why are you using it? You can apply the same actions to a movieclip that you can to a button. In fact, I never use buttons. I always use movieclips. They're much more flexible.
You should take a look at the following tutorials from Lee Brimelow of gotoAndLearn():
Creating Animated Buttons: http://www.gotoandlearn.com/player.php?id=28
Introduction to OOP: http://www.gotoandlearn.com/player.php?id=48
In the first, he'll show you how to use movieclips as buttons. In the next, he'll show you how to create an object-oriented class from it.
thosecars82
06-13-2008, 02:20 PM
That's a good thing. Your code should all be in the same place. If you're doing OOP, then in the same class per object.
Well there is no such thing as a home-made component, really. At least not in the sense that you're talking about. Plus what you're using is not the button component (that's a totally different thing). You're using a button object.
If you don't like the behavior of the button object, why are you using it? You can apply the same actions to a movieclip that you can to a button. In fact, I never use buttons. I always use movieclips. They're much more flexible.
You should take a look at the following tutorials from Lee Brimelow of gotoAndLearn():
Creating Animated Buttons: http://www.gotoandlearn.com/player.php?id=28
Introduction to OOP: http://www.gotoandlearn.com/player.php?id=48
In the first, he'll show you how to use movieclips as buttons. In the next, he'll show you how to create an object-oriented class from it.
Thks for the links, I am currently watching them.
Do you know how I can build an invisible button with a MovieClip?
What I meant wtih Home made button: I first made a shape on the stage and after that I convert that shape into a Button symbol.
thosecars82
06-13-2008, 02:31 PM
Thks for the links, I am currently watching them.
Do you know how I can build an invisible button with a MovieClip?
What I meant wtih Home made button: I first made a shape on the stage and after that I convert that shape into a Button symbol.
Got it! Like it was said in the first link you gave me, I saw that I can put a graphic inside a movie clip. And I can make the graphic invisible by changing the color of the graphic to alpha and setting 0% as percentage for alpha.
Thanks a lot
thosecars82
06-13-2008, 05:10 PM
Moreover, that site called http://www.gotoandlearn.com seems great. Thanks a lot. If you know any other useful site like that please tell me. At least for me, it is much more easier to see those videos than just reading text. So it is a good complement to flash documentation.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.