About telltarget and variables and stuff

ok… here is whats goin on… i am makin a site… and i have the menu drop down and the buttons and all… and i want it so when you click a button it will make a screen come down and then go back up if you click it again

i can make it come down, but i cant get it to go back up… i tried making a variable, setting it to true, changing it when the screen comes down, and changing it when the screen goes back up… a couple if statements should seperate the actions… but its not working…

here is the code that doesnt work…

on (release) {
if (up = true) {
tellTarget (“screen”) {
gotoAndPlay (“screen down”);
up = false;
}
}
if (up = false) {
tellTarget (“screen”) {
gotoAndPlay (“screen down”);
up = true;
}
}
}

also… im not sure where to create and initialize the variable… i’m thinking in the first frame of the movie clip with the “stop” command… please help somebody…

fix in code… um…

on (release) {
if (up = true) {
tellTarget (“screen”) {
gotoAndPlay (“screen down”);
up = false;
}
}
if (up = false) {
tellTarget (“screen”) {
gotoAndPlay (“screen up”);
up = true;
}
}
}

changed the second gotoAndPlay (was a typo)… anyway please help… thanks

2 errors I see : If (up==true) and if (up==false)
if (up=true) : that cannot work. Flash is stupid and does up=true (not a test !! it’s like if (5), it’s always true).

I’m not sure, but I believe that you should write up==“true”, since it’s a string.

  • 1 possible error : that gotoAndPlay, are you sure that the path is correct ? Well, if the darn thing comes down, it has to be.

pom 0]

true and false can be either strings or booleans.
when you type them in your actions screen without quotes they turn blue.
:slight_smile:
jeremy

yeah you can write true without the quotes, but Pom’s right, you have to have “==”, in those evals. a single equals changes the value, even in an “if” statement… confusing as that may be.

Oh, man, I totally forgot that flash handled boolean type… Anyway, I never use it, I prefer 0s and 1s. Numbers are always easier to manipulate than strings or boolean (I can sense from here Supra who’s going to come and tell me “No ! Not always ! Not if you take a multi-dimensional array or pointers !..”).

About that == thing, it is not THAT confusing once you’ve made the mistake 345,452,154 times. As “=” gives a value to a variable (don’t know the word in English), you have to have something else to test the value. Hence the “==”.

pom 0]

heh i totally forgot about the == thing… i am learning C++ so i should have known abou that… i changed the code but it still isnt working… when should i initialize the variable?.. i dont want to do it in the button because everytime it reads the code for it it will be reset… any ideas?

You’re saying that it comes down and then it doesn’t want to come up ?? That’s strange. And what variables exactly do you want to initialize ?
pom 0]

on (release) {
&nbsp &nbsp &nbsp &nbsp if (up == “1”) {
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp tellTarget (“screen”) {
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp gotoAndPlay (“screen down”);
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp up = “0”;
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }
&nbsp &nbsp &nbsp &nbsp }
&nbsp &nbsp &nbsp &nbsp else if (up == “0”) {
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp tellTarget (“screen”) {
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp gotoAndPlay (“screen up”);
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp up = “1”;
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }
&nbsp &nbsp &nbsp &nbsp }
}

i switched to else if because it was wrong the other way i realized… but its still not working…

Can you post the fla ?
pom 0]

lemme get your email ill send it you you… im not sure how to post it

on (release) {
//at the start, this will not be equal to anything, so it will
//not do screen up in the initial state.
if (up==1) {
//this is the new type of calling to movie clips.
screen.gotoAndPlay (“screen up”);
up=0;
}else{
screen.gotoAndPlay (“screen down”);
up=1;
}
}

I think that this will work better. you might need to add a “_root” in there before the word “screen.gotoAndPlay…”
but I don’t think so, if both the movie clip with the “instance” name of “screen”, and the button to which this script is added, both exist on the main timeline.
Tell target has been depreciated.
double check to make sure that your frames inside the movie clip screen, are labeled correctly. screen up, and screen down.

Other than that, it should work

He said that the sceen went down all right, so I don’t think this is a path problem.

The address, if this still doesn’t work, is [email protected]

pom 0]

Well, I eventually found what was wrong, and if you had listened to Upu, there wouldn’t have been a problem.

The thing is you use tellTarget (“screen”) {go down ;
up = 0 ;
}
But up isn’t located in “screen”. It’s located in _parent.screen !
Now let’s take a look at Upu’s code :
screen.gotoAndPlay (“go down”) ; // we’re inside screen
up = 0 ; // we’re in the correct movie clip

Forget about tellTarget, it’s really not half usefull as the dot syntax is.

pom 0]

wow… thanks alot pom and upu

i tried upu’s way after you changed it pom… it fixed one thing… cuz when you sent it back to me it played the up animation first… now it plays down first… but im curious… how come upu’s way doesnt require a root… but the other way does…???

??? Where _root ?? And it’s playing the screen the wrong way around ?? Hum…
pom 0]

oh… I figured that you’d want it to play downward on the first hit of the button as I thought that the menu would be in a “closed” state to begin with.

The alteration for making it go the other way first is pretty simple though.

on (release) {
//at the start, this will not be equal to anything, so it will
//not do screen up in the initial state.
if (up==1) {
//this is the new type of calling to movie clips.
screen.gotoAndPlay (“screen down”);
up=0;
}else{
screen.gotoAndPlay (“screen up”);
up=1;
}
}

When making calls like this, I like to think of my action script being used to “draw the attention” of the program.
“_root” before a chain of objects calls the attention of the program to the main timeline, and then each object up a chain must be called in turn.
“_parent” calls the attention backwards down a chain, as a relative address. That is, _parent.myMovieClip, refers to the timeline that contains whatever this code is located in, and then calls to a movie clip called “myMovieClip” in THAT timeline.

it’s a matter of going to the beginning and working your way up from there, or taking a step back and working from there.