PDA

View Full Version : if(.. prob again :(


Sonic_Mush
08-12-2002, 11:41 PM
understanding this seems so simple, i must be backing a key mistake somewere,

when ever i try making this code by myself it ALWAYS errors,

so heres the latest victim of an attempt


if (target("con")) {
(_currentframe == 2); {
gotoAndStop(15); }
} else if (_currentframe == 3); {
gotoAndStop(16); }
} else if (_currentframe == 4); {
gotoAndStop(17); }
}


it keeps telling me that

Unexpected '}' encountered
} else if (_currentframe == 4); {

and i have no idea why it is and how to fix it,
ive been pottering on this all day and still dont know,

so could so one either give me the answer and/or show me some tutorial that i havent found on if cmds

thxs in advance

xxlm
08-13-2002, 03:13 AM
if (target("con")) {
if (_currentframe == 2) {
gotoAndStop(15);
} else if (_currentframe == 3) {
gotoAndStop(16);
} else if (_currentframe == 4) {
gotoAndStop(17);
};
}



Ps:
if () {

}

always put the { } before writing the code... In that case you'll never have ) or { pb!

Sonic_Mush
08-13-2002, 12:19 PM
thxs xxlm the code itself has no errors but it still doesnt do the what it says,

theres no problem finding "con" because no errors occur (well no popups saysing cant find ....) and ive checked that the object itself changes between frames on command

so i cant understand why the script doesnt tell itself to go to the correct frame, "con" is on the same mov clip, just on a diffrent layer. so that it would constantly be there for another button to change.

iv tryed adding the "stop();" cmd before the cmd xxlm gave me but suprisingly all it does is just stop it

does anybody have an idea why?

could the second "if" have anything to do with it?

xxlm
08-13-2002, 10:54 PM
First, I have a question... What is "con"? I think your condition is not good...

Second, the second if is a example of how writting the code... Do this and after add code in it, in that case never had a { or ( pb... See what I mean?

What do you exactly want to do?

Abelius
08-14-2002, 03:38 AM
Use "switch"...

xxlm
08-14-2002, 04:03 AM
yep, you can use switch...
But I use it for 4 or more condition. Depends of your preference.
;)

Sonic_Mush
08-14-2002, 12:21 PM
what is switch? for a start,


im trying to use a peice of animation for each of the menu buttons, the only diffrence is the last frame on the animation wich has the links to the specific area depending on the button pressed,
eg press links, animation-links to more links
press lab, animation-lab links

so i put the code on the frame before the dependent frame (the code ur dealing with) which should go to the frame coresponding to the button pressed by use of "con".

"con" changes frame depending on which button is pressed (its just a mov clip) its on another layer inside the animations mov clip and i know that it changes because i put a number on each frame which changes corresponding to the button.

eg links pressed tells "con" to go to frame 2 and stop
lab pressed tells "con" to go to frame 3 and stop
.....


i dont think ive explain it very well i can included a swf if u want
p.s sorry it took so long 4 me 2 reply

xxlm
08-14-2002, 01:38 PM
switch ... look at your help. You can use it when you've got several (same) condition like yours.

Else, send your fla!

Sonic_Mush
08-14-2002, 02:31 PM
ive inlcuded a smaller version of the .fla i hope u can make it work

tg
08-14-2002, 05:24 PM
do this anytime you are having a problem:
trace(target("con")); just to check what your 'if' statement is seeing.

when you run this (right before your if statement) it returns 'undefined'
since 'undefined' is not true, your if statement is not executed.

the problem is most likely a pathing statement to

lets try something here. lets try to get rid of all the old syntax your using, it will make things way more legible.

so change all your statements:

telltarget("mymc"){
gotoAndPlay(#);
}
//to:
mymc.gotoAndPlay(#);


they do the same thing, the second is just more clear and easier to read. its also the 'standard' way to do it in mx.

in your if statement:

if(target("con"))
//i think should be:
if(con)

this if statement of course only checks to see if there is an object called 'con' defined within the scope of the if statement, so if the path to the object is incorrect, if will return false, and the statemtents inside your if will not execute.

the next part of your if statement:

if(_currentFrame==2) //is this in reference to _current frame of con?
//if so then it should be if(con._currentFrame==2)
//otherwise flash is doing: if(this._currentFrame) -- looks at the current time line to see which frame it is on.
//then of course there is the action to execute if the expression is true:
gotoAndStop(15);
//now this will gotoand stop on the current timeline that this statement is on.


it may help you out to review the paths tutorial on this site.

hope it helps... hope this didn't sound to brutal... wasn't supposed to be.

Sonic_Mush
08-14-2002, 06:03 PM
thxs, its not brutle,

i just thought that because flash didnt send me any errors "cant find etc" that the pth was correct.

but how do i add an "else if" cmd? i havent used flash much as u can c by my site,

any hows why iss the script redondent? mx just changes it bck to the style im used to when i auto format it

tg
08-14-2002, 06:10 PM
don't have time now, maybe i can explain some of this stuff later.
for now, go through the first 5-10 tutorials in the beginning section. it should give you a good start. make sure you have a full understanding of most of the tutorials in the beginners section, and you will have no problems with what you want to do.

i will try to catch you later.

xxlm
08-15-2002, 02:41 AM
Why don't you use a global var named ie LastClick ?
Then when you have to check which button has been clicked look at this var...