View Full Version : How to use an "if" statement properly

01-24-2002, 11:24 PM
I hope that someone here can assist me or direct me in the right direction in order to finish my project. As I am still learning ActionScripting I will do my best to explain this little dilemma of mine, Thank you...

I am using both Flash 4 and 5 w/Windows 2000 in creating a CD project that uses a door like interface, and I'm having trouble figuring out how to open and close this door that reacts to multiple commands? I wish to open and close the door each time the user clicks a button to see a menu or other items within the movie.

I have been able to figure out how to obviously open and close it with a tellTarget or evaluate command. But I can't get the door to respond and re-open again once the requested file or movie is loaded (it just stays closed)?

There has to be a way to do this as I've seen similar ideas on the web, I figure with maybe an "if" statement perhaps, I could do this but I don't know how to script that???

Do you folks have any examples of code or ideas that I could try. I'd greatly appreciate it,


Billy T
01-24-2002, 11:31 PM
this might help

couple of threads down (http://www.actionscript.org/forums/showthread.php3?s=&threadid=8587)

red penguin
01-24-2002, 11:31 PM
Well, as someone I know likes to say..there are a thousand ways to skin a cat...Is your "door" a MC? if it is, then you could just each time a button is clicked tell it to play, yeah?

01-24-2002, 11:44 PM
Hello, thanks for the quick response. I have been able to tell the door to "play" but for some reason my door stays closed once the new file is loaded. So I guess the problem that I am having is the ability to click a button and have the door close, load the requested .swf file and then have that file tell the door to open.

I hope that helps explain my idea. For an example, try out this site here and browse thru their menus and watch how the "door" works:

as they have created something similar to what I would like to accomplish. This may be a very simple thing to do, so please accept my apologies for my ignorance.

Thanks for the help,

red penguin
01-24-2002, 11:51 PM
So then, if bytes loaded equals total bytes play the opening sequence...

01-25-2002, 12:02 AM
Hey there,
I think I follow, but only to a certain extent? Where or how do I use the "if bytes loaded equals total bytes play the opening sequence"?

I'd imagine you mentioning "opening sequence" is refering to my "door" right? If so then where or how do I use the if statement?

As I've mentioned earlier, I'm not completely sure on how to script the if statement and where to properly place it? In each MC, in the buttons, in the door MC? Again sorry bro, I am trying my best here.

Thanks alot for the help...
p.s. I will take a look at that file you posted earlier Billy, thanks....

red penguin
01-25-2002, 12:35 AM
Okay, so it's late and I need some sleep before the office tomorrow...I'll get back then...Deal?

01-25-2002, 01:59 AM
Hey there Komi,
Yeah that's fine, I'll look forward to it. Hope I don't lose you to fast though? Thanks for the help, talk to you later....

01-25-2002, 05:09 AM

What a cool site!!!! Golly gosh.

I figure you could just get the newly loaded swf to tell the main to play the door thing or whatever. I think Komi was thinkin' you had some sort of a preloader in the loaded swf's. Normally you'd have some loop in the first frames (or however you want to do it, blah, blah, blah...) to find out if the whole movie has been downloaded in it's entirety, and therefore ready to do it's stuff. At this point it should tell the door to open.

red penguin
01-28-2002, 07:59 PM
Have you seen the preloading tut on this site?
This should be on the loading .swf followed by a "gotoAndPlay(_currentframe-1);" to get that loop we need
...the first three lines can be omitted if you don't want to show the progress in textfields in that movie
...notice that "ifFrameLoaded" corresponds to _level1 which is where the movie is being loaded...

total_bytes = _root.getBytesTotal();
loaded_bytes = _root.getBytesLoaded();
percent_done = int((loaded_bytes/total_bytes)*100);
ifFrameLoaded ("whateverframeyouwishtobetargeted", 1) {
stop ();

I also made a small file which uses the onClipEvent(data) event handler but works when loading something into an emptyClip and I don't think that's what you're after...after re-reading this...

01-29-2002, 08:35 AM
Hello Komi,
Thanks alot for the help here, as I've mentioned earlier. I am not all that swift on ActionScripting as of yet. Getting there! Curious, will this work on or for external .swf's???

Ok now, yes I have gone through many of the Tut's on this site. However I get a bit lost sometimes. Now with this code you mention above, I put it into the .swf that is TO BE loaded (I imagine into Frame 1 - right)? Do I then put "gotoAndPlay(_currentframe-1);" into frame 2??? Where does that go? You see.... this is where I get lost. Sorry.....

About that small clip you created? I may be after such a thinig as I am loading external .swf's, and when loading a movie, doesn't the .swf HAVE to be loaded into an "empty clip" in order for Flash to know where it is going to be placed and so that it doesn't replace any existing scene(s)?

I really appreciate your help here dude....
Thank you very much :D :D :D

red penguin
01-29-2002, 12:25 PM
You have the option of either putting it in a _levelx or parking it in an empty clip...Either works, just depends on what you want to do, really...if you are going to want to manipulate it's props, then mc would be the way to go...I suppose it just depends on the content, really...Hey, at least we have the choice!....

You are correct, sir...The code would be placed on the first frame of the movie being loaded...that wasn't clear?....followed by the gotoAndPlay(_currentframe - 1);

01-29-2002, 07:48 PM
Hey there,
Sorry for the late response, I was up late - working with AfterEffects. I have tried out the code and used it in a clip that is being loaded on request to _levelx, just as you explained. The clip loads just fine (of coarse sometimes faster than the door closing - ARGH!) when I click the button that corresponds to it. However the door does not open when the clip is finished loading.

I have placed the code from above into frame 1 of external.swf A, then I placed gotoAndPlay (currentFrame-1) into frame 2 of this same movie. What have I missed?

As always, thanks for hanging in there and helping me out...
Tom ;) :p

red penguin
01-29-2002, 10:11 PM
Where is this button and what is the code? Is the button controlling the door?

01-30-2002, 11:30 AM
You have made my week! :D It works, but I found some syntax errors in the code that I typed in the "loading.swf". I used a set variable, rather than typing just an expression. I found that I could only type this expression in "expert mode", isn't there a way to type expressions in "normal mode", maybe not?

I have made some success, yepee! Sorry about "beating the dead horse" here, but if you don't mind, I would like to clarify a few things? I have multiple buttons that are located in an MC that I have placed into _level0. I would like to control the door from each of these buttons independently. The buttons are as follows:

Access | Library | History | Knowledge | Performance

The code for each is like so:
on (press) {
tellTarget ("/_door") {
gotoAndPlay ("close");
on (release) {
loadMovie ("whatever.swf", _target);

Note: The reason for using a tellTarget is because I'm not great at using dot syntax yet, especially when I have buttons or MC's in the main timeline.

Then in the "loading.swf" I used the code you provided from above.
Frame 1:
ifFrameLoaded ("whateverframeyouwishtobetargeted", 1) {
stop ();
Frame 2:
gotoAndPlay (currentFrame-1);

1. When you mention "whateverframeyouwishtobetargeted" - do you mean the scene name?
2. The number 1 that follows, represents the level or frame number?
Thank you so much, this is really helpful....
p.s. I'm sure that I'll have more questions later on - :rolleyes:

red penguin
01-30-2002, 03:25 PM
That IfFramesLoaded thing was bothering me and now I know why. It's being depricated in favor of...

if(_framesloaded == _totalframes){
} else {
gotoAndPlay(_currentframe - 1);

Does that help?

01-30-2002, 08:07 PM
Ah, much better.... You see, I'll get the hang of this sooner or later... :p

Two thumbs up for Mr. Red here!
Thank you very much for your help, and for sticking through this for me.

"Patience and tenacity of purpose are worth more than twice their weight of cleverness."

Again thank you,