Join Login


Premiere Pro CS5
 Multiple Toggle buttons
 by cdolphin09 - Apr 14, 2011

Yea, its me again =/

Im really sorry, I have so many projects at hand right now... so I am basically staring at my flash 24/7. You are a life saver :D

Ok, So.. I have a project that includes toggle buttons. (oh and I am in AS3 this time :)) I have the first toggle button working, but I cant seem to get the rest to work.
I have about 9 buttons and each toggle out to an image.

My first two button instance names are : FP1btn & FP2Fbtn
My first two movie clip names for those buttons are: FP1window & FP2Fwindow

This is my code for the first button right now:

FP1btn.addEventListener(MouseEvent.CLICK, toggleContent);

function toggleContent(event:MouseEvent){
if(FP1window.currentFrame == 1){
FP1window.gotoAndPlay(2);
}
else{
FP1window.gotoAndPlay(12);
}

}

---- I know that one button can use the same event listener function. So I tried this code for the first two buttons:

FP1btn.name = "btn1"
FP2Fbtn.name = "btn2";

FP1btn.addEventListener(MouseEvent.CLICK, toggleContent);
FP2Fbtn.addEventListener(MouseEvent.CLICK, toggleContent);

function toggleContent(event:MouseEvent){
if(event.target.name == "btn1"){
if(FP1window.currentFrame == 1){
FP1window.gotoAndPlay(2);
}
else{
FP1window.gotoAndPlay(12);
}
}
else if(event.target.name == "btn2"){
if(FP2Fwindow.currentFrame == 1){
FP2Fwindow.gotoAndPlay(2);
}
else{
FP2Fwindow.gotoAndPlay(12);
}

------

Where am I going wrong?

Thank you so much!

Btw, your tutorials are the bomb!

=D





cdolphin09
United States
Posts:19
Joined:Mar 28, 2011
 RE: Multiple Toggle buttons
 by RiverCityGraphix - Apr 15, 2011

I think the problem lies in the fact that you are re-naming the buttons. It might just be easier to copy each function in the long run. What you have is a little tricky to work out so it might save time by using multple functions.


Be sure to subscribe on YouTube.

Do you take great photos? Consider selling them on Dreamstime.
RiverCityGraphix
United States
Posts:327
Joined:Nov 21, 2009
 RE: Multiple Toggle buttons
 by DVictor14 - Apr 15, 2011

toggleContent
toggleContent
toggleContent
change them...like this:

toggleContent1
toggleContent2
toggleContent3

they mustn't be the same ;)



DVictor14
Romania
Posts:55
Joined:Mar 15, 2011
 RE: Multiple Toggle buttons
 by DVictor14 - Apr 15, 2011

i think this is the probleme...you should try it ;) :)

Have a good time,
Victor :)


DVictor14
Romania
Posts:55
Joined:Mar 15, 2011
 RE: Multiple Toggle buttons
 by cdolphin09 - Apr 15, 2011

Thank you so much!! I got it to work!

I did what you both had suggested. I omitted re-naming each of the buttons, then I gave each togglecontent it's own name, and then I added a bracket that was missing.

Here is the script that ended up working:

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

FP1btn.addEventListener(MouseEvent.CLICK, toggleContent1);
FP2Fbtn.addEventListener(MouseEvent.CLICK, toggleContent2);

function toggleContent1(event:MouseEvent){
if(event.target.name == "FP1btn"){
if(FP1window.currentFrame == 1){
FP1window.gotoAndPlay(2);
}
else{
FP1window.gotoAndPlay(12);}
}
}
function toggleContent2(event:MouseEvent){
if(event.target.name == "FP2Fbtn"){
if(FP2Fwindow.currentFrame == 1){
FP2Fwindow.gotoAndPlay(2);
}
else{
FP2Fwindow.gotoAndPlay(12);}
}
}

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

Thank you so much!

--Cristina--


cdolphin09
United States
Posts:19
Joined:Mar 28, 2011
  
Home About Contact Forum Youtube Privacy Policy
Copyright © 2009-2011 RiverCityGraphix.All Rights Reserved.