View Full Version : Defining variables/actions in external movies
setzer9999
April 20th, 2008, 09:29 AM
Hey everybody,
I have a question about movies loaded to the main movie via loadMovieNum.
1. I have a movie, called "index.swf", another movie called "main.swf", and another movie called "about.swf"
2. On the only frame in "index.swf" I have the code
loadMovieNum("main.swf",1)
3. On a specified frame in "main.swf" I have the code
loadMovieNum("about.swf",2)
4. In the movie "main.swf" I have a button with this code
[quote]
on(press){
//to unload movie "about.swf"
unloadMovieNum(2);
//to continue to the next frame of "main.swf"
gotoAndPlay(19);
//code related to "main.swf"
var skip2:Boolean = new Boolean();
skip2=true;
}
5. I do not want "about.swf" to simply unload and disappear though. I would like for the button in "main.swf" to be able to create a Boolean value within "about.swf" and tell it to play the next frame and finish playing the movie to the end before unloading the movie. With the parts I don't know actionscript syntax for, the English translation of the code might look like what is between the *english* tags:
on(press){
*english* Create Boolean variable in current frame of "about.swf";
play next frame of "about.swf";
only when "about.swf" is complete (has reached its final frame) then do next
line of code on this button;*english*
unloadMovieNum(2);
gotoAndPlay(19);
var skip2:Boolean = new Boolean();
skip2=true;
}
I hope the idea of the *english* tags help and don't confuse. Thanks for reading! I'm a complete amateur at this, but I'm not just copying code to do something. I'm learning how to apply this code in multiple ways, so I hope no one finds me annoying. This forum is great.
glosrfc
April 20th, 2008, 09:50 AM
You're not annoying...at least, not yet ;)
It's always a good idea to learn by applying your own code. However, there are some things that you need to understand first because it will really help you in future:
1. You're using an old-style method of attaching code to symbols. While that's acceptable, it makes it extrememly difficult for you to keep track of what code your file contains and where it is. You should adopt the best practice of placing all of your code into the first frame of your main timeline.
2. This means that you will have to learn dot notation, which is quite easy to pick up. Let's assume you have two buttons on your stage. At the moment you place individual pieces of code onto each button to capture the mouse events, e.g.
on(press){ // attached to button 1
gotoAndPlay(9);
var skip1:Boolean = new Boolean();
skip1=true;
}
on(press){ // attached to button 2
gotoAndPlay(19);
var skip2:Boolean = new Boolean();
skip2=true;
}
As you add more buttons, your code will become even harder to find and to debug. A far better method is to give your two buttons instance names, e.g. my_Btn1 and my_Btn2. You can then place the following code into the first frame of your main timeline:
my_Btn1.onPress = function();
gotoAndPlay(9);
var skip1:Boolean = new Boolean();
skip1=true;
}
my_Btn2.onPress = function();
gotoAndPlay(29);
var skip2:Boolean = new Boolean();
skip2=true;
}[/code]
3. Are you really sure that you want to use Boolean values? You can assign any value to a variable - they don't have to be Boolean values. A Boolean is simply a switch...true or false...1 or 0...on or off.
setzer9999
April 20th, 2008, 11:09 AM
Wow, glosrfc. I learned another thing about buttons I never knew to ask.
That dot notation is easy. In 2.0 its easy to give things instance names. I'll do that the next time I make a movie. Thank you very much.
I would be open to learning a better method of allowing tweens to complete then skipping to a specified frame based on the button pushed, certainly. However, I am in school right now and trying to finish an assignment for which there is little instruction. I am a graphic design student, and at my school we are expected to create a flash site, but the instruction we receive is completely limited to animations, timeline, and VERY simple code.
I am in a bit of a time crunch, and all I've managed to learn so far by asking questions based on my limited knowledge is Boolean values. I coded the entire menu already in that fashion and it works repeatedly from any point.
I don't know if what I asked in this particular thread is possible, to have one movie add objects or variables into another movie that has been referenced. If it isn't, the site will just look slightly less aesthetically appealing, but still function just fine.
I'm sorry if you are cringing at the thought of my site using all those Booleans and deleting them because you are so much better than that at it. I'm sure if I keep learning at the pace I'm learning at with all of your help, I won't make another site that way in the future.
glosrfc
April 20th, 2008, 11:32 AM
There's nothing wrong with using booleans - it's just that you're possibly making the logic more complicated than it should be if you use them.
As for allowing tweens to complete before you skip to another frame, that's precisely what you're doing by storing the target frame number into a variable. Your tween between frames 2 - 8 will still run but, when the playhead reaches frame 8, it's then directed to the target frame number that you've stored in your variable. No need to use loads of boolean values at all.
And I'm not cringing...it's not my site ;)
Storing the frame number into a variable (and using dot notation) would also make it so much easier to reference variables that are in another swf. You should probably also use loadMovie so that you can create an instance of the loaded movie rather than loadMovieNum. For example, using your english notation:
on.press // button is pressed
targetFrame = 29;
loadMovie("about.swf", placeHolderMC) '// placeHolderMC is a blank movieclip residing on your stage
if (placeHolderMC.currentframe == placeHolderMC._totalframes) // check if the loaded MC has finished playing
gotoAndPlay(targetframe); // move the playhead to the target frame
Hope that helps.
setzer9999
April 20th, 2008, 12:16 PM
Yes, that certainly did help. I believe I understand how the code you described will check to see if the loaded movie is at its final frame before the base movie will move to the specified frame. That is wonderful!
Only one piece of the puzzle remains. I want the button in "main.swf" to tell the movie "about.swf" to do something within itself.
1. Say I have a stop(); in the "about.swf" on frame 10
2. There is a Boolean variable defined on frame 10 as well
3. The Boolean looks like:
on(press){
gotoAndPlay(11);
var skipa1:Boolean = new Boolean();
skipa1=true;
}
4. On frame 20 there is this code for the Boolean();
stop();
if(skipa1 == true){
gotoAndPlay(2);
}
if(skipa2 == true){
gotoAndPlay(21);
}
5. The second condition defined on frame 20 for the Boolean does not have a variable defined in the movie "about.swf". This is no accident. I want to have the button that does the code you provided, glosrfc, also imput a Boolean variable into "about.swf" on fame 10.
Frame 21 is the last frame in the movie, so based on the code you already helped with, that would immediately terminate the movie and restart the playhead on "main.swf"
6. I suppose the code would look like this with the *english* that is still missing
//frame in "main.swf"
loadMovie("about.swf", placeHolderMC)
if (placeHolderMC.currentframe == placeHolderMC._totalframes)
unLoadMovie("about.swf", placeHolderMC)
//button in "main.swf"
on(press){
*english* Add a Boolean value into the current frame of "about.swf, placeHolderMC., rather than the current frame of "main.swf"
The Boolean value would be:
var skipa2:Boolean = new Boolean();
skipa2=true;
Then after the Boolean value has been remotely entered, also have this button remotely tell the "about.swf" file to gotoAndPlay frame 11 *english*
Essentially I want the button in "main.swf" to add a variable to the current frame in "about.swf" and then advance the playhead in "about.swf"
Thank you so much for your patience and great answers.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.