Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sliding panel 2

Status
Not open for further replies.

law78

Technical User
Apr 23, 2004
78
GB
Hi people,

I am sure this is a simple query but I just can't get my head round working it out, I am pretty new to AS, maybe thats the problem:
I have four button links which trigger off a sliding panel (movie), how can I give Flash the intelligence to know which was the last button clicked so that it can send the previous panel back to its original state as well as slide the current one out? Hope this makes sense, here is an example:


Have they used an if / else chain to work out which one to slide back in (the links)

I have been trying to work this out for nearly 5 hours... AHHHGGG

Help
Thanks
 
I think you should create a global variable for each of the "sliding panels". Initially, set all of them to the same value - doesn't really matter what this value is but for examples sake, we'll set it to 0 (zero). Now, add a line to each of your button actions that would set the value to 1 for the respective panel. Don't forget to set all the other panel variables to 0 (zero) at the same time. Now, add an if/else if/else statement that tests the values of each of the variables and open the correct sliding panel.

There's always a better way. The fun is trying to find it!
 
I think I will have to sit down with my ActionScript book for this one, I know a little about variables but I have never really used them.

I think I understand what you mean, thanks for your help

Lee
 
Here's a little example...

in the first frame of of the main timeline, do this:
Code:
_global.sp1 = 0;
_global.sp2 = 0;
_global.sp3 = 0;
_global.sp4 = 0;

The reason for a global variable is that it can be used by any part of your flash movie without having to use _root or _level to access it.

Now, for your buttons:

Code:
on (release) {
sp1 = 1;    // sets the variable for sliding panel #1
sp2 = 0;    // set the other variables to 0
sp3 = 0;    //  ''  ''   ''     ''       ''
sp4 = 0;    //  ''  ''   ''     ''       ''

if (sp1 == 1){gotoAndPlay("panel1");}
else if (sp2 == 1){gotoAndPlay("panel2");}
else if (sp3 == 1){gotoAndPlay("panel3");}
else {gotoAndPlay("panel4");}

I doubt seriously that I've named everything correctly for you movie but this shows one method to go about determining which sliding panel to open.



There's always a better way. The fun is trying to find it!
 
wow your a legend, I had awuick look at my book and it didn't really make sense but your code has just made me understand it,

Thanks
Lee
 
The last bit of code, is that attached to each individual button, but I just change the code to refelct which button its attached to i.e.

// button 1 code
sp1 = 1;    // sets the variable for sliding panel #1

button 2 code
sp2 = 1;    // sets the variable for sliding panel #2

Sorry, I know I'm lame when it comes to AS

tHANKS
 
Thanks for the praise but I really don't deserve being a legend - at least not in Flash. The real legend here is oldnewbie - compared to him, I'm a rank amateur!

Anyway, glad I was able to help you turn on the lights. Good luck with your project.

There's always a better way. The fun is trying to find it!
 
With my limited variable knowledge I have just done what you recomended but I can't get the last sliding panel to slide back when the next one is clicked,
If possible, I want Flash to know which was the last button pressed and then send it back via a label in the Movie timeline named back, if this is too dificult then simple remove the last movie clip.
Here is the code I have inc. so far:
This is what I added to the first frame on the main timeline
// declare the variable for holding the slide intelligence
_global.click1 = 0;
_global.click2 = 0;
_global.click3 = 0;
_global.click4 = 0;
Here is the code attached to the button(s)
on(rollOver){
slideout1_mc.gotoAndPlay("roll");
}
on(rollOut){
slideout1_mc.gotoAndPlay("back");
}
on (release) {
click1 = 1;
click2 = 0;
click3 = 0;
click4 = 0;

if (click1 == 1){
click1_mc.gotoAndPlay("roll");
}
else if (click2 == 1){
click2_mc.gotoAndPlay("roll");
}
else if (click3 == 1){
click3_mc.gotoAndPlay("roll");
}
else {
click4_mc.gotoAndPlay("roll");
}
}
 
Well, with my limited know-how, your script will always play whatever is in the "roll" frame. In order to play the last panel that was last pressed, you'll have to create a new layer/frame for each panel and call it in the if/else routine. You could, of course, set a variable with the name of the last panel rather than which button was clicked. Then, with your 'back' button, you would open whatever was in that variable.

There's always a better way. The fun is trying to find it!
 
tviman:

Is there any chance you could look at my fla file and see where I am going wrong?
 
Set it up for download and supply me with a link. Best to zip it first.

There's always a better way. The fun is trying to find it!
 
Okay, I think I understand what you want. See if I have it correct:

Assuming a fresh page load (just the buttons 1 thru 4):
press button 1 and a menu rolls out.
press button 2 and menu #1 rolls back, then menu 2 rolls out.
the same for subsequent "clicks".

so that only one menu at a time is showing.

Am I correct in this?

There's always a better way. The fun is trying to find it!
 
Yeah thats right, I just don't know how to script that in Flash, although its not in any order eg. if you go into the page then click button 2 followed by button 4, I would like flash to be able to roll back button 2 as button 4 rolls out, I think you have the idea though.

 
Good - this is simpler than I expected. In your actionscript for button 1, do these things in the order listed:

1 - check to see if the MC is on frame one - if(_root.mc_instance_name1._currentframe == 1)

2 - set all other MC's back to their beginning frames - _root.mc_instance_name2.gotoAndStop(1)
_root.mc_instance_name3.gotoAndStop(1)
_root.mc_instance_name4.gotoAndStop(1)

3 - start MC #1 - _root.mc_instance_name1.gotoAndPlay(2)

Now, do this for each of the buttons - they should look something like this:

button #1:

Code:
on (press) {
  if(_root.mc_instance_name1._currentframe == 1){
     _root.mc_instance_name2.gotoAndStop(1);
     _root.mc_instance_name3.gotoAndStop(1);
     _root.mc_instance_name4.gotoAndStop(1);
     _root.mc_instance_name1.gotoAndPlay(2);}}

button #2:

Code:
on (press) {
  if(_root.mc_instance_name2._currentframe == 1){
     _root.mc_instance_name1.gotoAndStop(1);
     _root.mc_instance_name3.gotoAndStop(1);
     _root.mc_instance_name4.gotoAndStop(1);
     _root.mc_instance_name2.gotoAndPlay(2);}}

button #3:

Code:
on (press) {
  if(_root.mc_instance_name3._currentframe == 1){
     _root.mc_instance_name1.gotoAndStop(1);
     _root.mc_instance_name2.gotoAndStop(1);
     _root.mc_instance_name4.gotoAndStop(1);
     _root.mc_instance_name3.gotoAndPlay(2);}}

button #4:

Code:
on (press) {
  if(_root.mc_instance_name4._currentframe == 1){
     _root.mc_instance_name1.gotoAndStop(1);
     _root.mc_instance_name2.gotoAndStop(1);
     _root.mc_instance_name3.gotoAndStop(1);
     _root.mc_instance_name4.gotoAndPlay(2);}}

What this does is send any "open" menu back to it's start and opens the menu that waas clicked. The added side effect is that it won't "reopen" a menu that's already open.

Hope this helps you out. You'll have to make some changes, I'm sure, to accomodate the rest of the functionality of your page.

There's always a better way. The fun is trying to find it!
 
Never thought about doing it that way, it's a lot simpler than the ways I have tried.

Thanks
 
Glad to be of help. I'm certain that there are other, and probably better, ways to accomplish this and I have to admit that I ran into a very similar problem just two weeks ago. Just goes to show that if you assign the same problem to 10 different programmers, you're very likely to get 10 different solutions to the same problem.

There's always a better way. The fun is trying to find it!
 
tviman:

Not sure your way actually works, the problem is that there is movement on the slide back transition (when clicking from one button to the other), the way the above code is set out, it will simple stop all the other button states at a non sliding frame.

what I need to get flash to do is send the playhead of the last selected movie to the frame label back, where I reverse of the click animation will take place i.e. panel goes back and fades out.

The only other option I could use with the above code is to sacrifice the back animation.
 
No, not at all... just send the play head to the frame number that starts the transition to fade out. If it happens to be frame 30, then set it to that number. What you might have to do is check the position of the current frame of all other movie clips so that you don't activate them when they weren't open in the first place. Then, in that particular movie clip, when it reaches it's last frame, issue a gotoAndStop(1) so that the playhead for that MC is at it's beginning, ready for the next "click".

There's always a better way. The fun is trying to find it!
 
Thanks,

Thats what I am doing now, you pointing out the _current frame command is helping me loads, I am just getting a few errors in my actionscript,

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top