Jump to content

Drop down back to inital state inside Movie Clip


rzea

Recommended Posts

Hello all,My Case:I have a US Map and several states are clickable, when you rollover a state it changes from yellow to red (this is a MC). When you click a state it stays red and a box 'drops down' from it with a body text explaining something about it (this is another separate MC). The box can be close in two ways: 1. By clicking on the state again. Or 2. By clicking on an X that the box has.My problem:I can't find a way to close the box via the X.The Explanation:The box with the text and the X are all a Movie Clip, this MC is activated by clicking on the state on the main Time Line, but I don't know how to make the X close the MC it's contained in (the drop down box). I can close the box from outside (main Time Line) by clicking the state though.Does that make sense?You have to consider that the X ' wouldn't ' know when the box is contained in is either open or closed... which is actually the piece of ActionScript that I need.The code I'm using:This is the code I'm using on the state to open and close the box containing the explanatory text, and the closing X of course:

on (release) {		if (Number(test) == 1) {		test = 0;	} else {		test = 1;	}}

My problem:As I mentioned, I don't know how to use the above code and use it inside a MC to make the box close itself if it's open... the X to close the box can only be seen when the box is open or has dropped down.Can anyone give me a hand please?Download the FLA:To understand better my problem you can download the original file from here: http://www.ricardozea.net/map/map.zipAny help will be greatly appreciated.Thank you!

Link to comment
Share on other sites

The X doesn't need to know if the box is open, if someone is clicking on the X then the box is open. That code doesn't open and close the box though, it just toggles a variable between 0 and 1. You can use _parent inside the action for the X to hide the box, however you do that. I'll use the _visible property, but you can adjust it to use the code that actually closes the box.

on (release){  _parent._parent._visible = false;}

You just need to use the correct path, if _parent._parent isn't correct then substitute whatever the correct path is from the X to the box, and you can either set _visible to false or gotoAndStop on a blank frame or whatever you do to close the box.

Link to comment
Share on other sites

Almost!I had to modify your idea to "_root.bellevuelyr._visible = false;", your code didn't work.However, although the modification based on your idea worked, it didn't work all the way.The problem is that when I hide the box (or make it 'not visible'), the box is still open, so when I try to open it again by clicking on the state nothing happens because the box is not visible anymore.By the way, the X is inside the MC of the box because when the box drops down then at certain point the X appears.Dang... this is really stressful.Thanks again for any help you could give me.

Link to comment
Share on other sites

Yes, I realize that what I posted wasn't going to work exactly like it is, which is why I said to change it to add the correct path and do the same thing that normally happens when the box closes. It sounds like the visible property isn't used for that, so you shouldn't use it to close the box.I can't open your file with Flash 8, so I can't check the code. But what you need to do is find the code that normally closes the box when you click on the state again, and use that same method to close the box with the X. You can use one or more _parent references if you don't want to use _root, if the X is inside what you want to close then using _parent will get you there if you know how many times to use it, otherwise you can use _root like you already are if the box will always be on the root level. But the point is to find the code that normally closes the box and do the same thing when you click on the X. Obviously it's doing something more than just setting visible to false.

Link to comment
Share on other sites

Here, I saved the file as Flash 8, you can download it again: http://www.ricardozea.net/map/map.zipThe code I'm using to close/open the box is this one:

on (release) {		if (Number(test) == 1) {		test = 0;	} else {		test = 1;	}}

I have placed this code on the X that should close the box, but it doesn't work, probably is because it's inside the MC but I can't take it out because the X appears at a certain moment when the box is dropping down.If you open the file, you'll see there's a later with some actions that are triggered by the code I mentioned above.Thanks for your help.

Link to comment
Share on other sites

Dang!!! I MADE IT!!!!Editing...EDIT --Yes "justsomeguy", you were totally right, I just had to add "_root." to the same code :).This is what I did to make it work:

on (release) {	if (Number(_root.test) == 1) {		_root.test = 0;	} else {		_root.test = 1;	}}

My problem is(was) that I didn't really understand the concepts of "_root." and "_parent." until I read your suggestions. Now I know that "_root." means 'pointing to the main timeline', and "_parent." something like 'pointing to the parent MC that contains me', right?Oh man, not understanding these kind of concepts really makes it difficult to get something simple done.Thanks for your help "justsomeguy", appreciate it.

Link to comment
Share on other sites

That's right, _root refers to "level 0". Flash puts everything in levels, and level 0 is the base stage of the movie. If you have a movie called "mc1" and you put it on the stage, you can refer to it as _root.mc1. If you put a trace statement to write out mc1 like this:trace(mc1);It will print something like "level0.mc1". If mc1 has a movie clip inside of it called mc2, and if mc2 has a movie clip called mc3, then inside mc3 you can have code that refers to mc1 using _parent._parent. So if you have a variable inside mc1 called test and you want to put it in a text box inside mc3, then the code in mc3 would look something like this:textbox.text = _parent._parent.test;So _parent would refer to mc2, and _parent._parent would refer to mc1, from mc3. If you want the code to be in mc1, then it would look like this:mc2.mc3.textbox.text = test;So both of those lines refer to the same things, they just refer to them from different places so the path to "find" those things needs to be different. This is called scope. _root is a certain scope, or an object has a local scope that contains all of the things inside that object itself (I guess _root would be the "local" scope of the entire Flash movie). _parent would refer to the scope one level up from the current object.The reason why it's good to use that is so that you can embed mc1 wherever you want (not necessarily on _root) and it will still work. You can also use _root.mc1, but if you move mc1 into another movie clip then _root.mc1 will be undefined.

Link to comment
Share on other sites

Yes, I understood it because it resembles CSS structures when referring to an HTML element that's inside several HTML tags, IDs and classes, so to style it you need to specify the entire list of HTML tags, IDs and classes.Very nice explanation justsomeguy, thanks a lot for your time.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...