Flash Professional 8 - How to Keep Your Script Organized
Video Transcript
Now, that is well and good but one thing that we are going to be doing is we are going to be moving this script around. Now, you can kind of imaging in a program where you have got lots of button for navigation and other buttons that control all kinds of things. If you continue on the way that we have started, we will have little pieces of action script all over our program.
We have some of it on this key frame, so in that key frame. Some of them on this button and it kind of gets splintered and pull out. So, the last fundamental that I would like to go over is how to move this script to a common location. Where it is going to be easily accessible.
Now for right now, I am just going to type this syntax in but I would like to go out of script this is mode and the first thing I would like to do is remove this script from our code right now. So I am going to cut it, I will just use my edit cut, and I am going to bring my timeline window back up because what I would like to do is I like to go back to the place where all of my other script is.
This would fit under the best practices heading that I introduce before. It is not going to work any better necessarily to move your script into this location but I think most of you could imagine that if you could open up your flash movie file and find everything your flash movie file does an action script under one location. That is much better than going around and looking and hunting in packing for all the little pieces that you have left.
To get the same script to work here we are going to need a little bit different syntax. I am going to down to the next line and I will paste in what we copied from our last one.
We put a line in between here and I will add a comments so we know what is going on. I am going to set up the buttons.
Now, from just looking at this script you can kind of imaging one thing that might be a problem here. Before we set on release but we did not have to say what we would be releasing because it was connected to the button directly.
Now, I have to specify what this function is going to be attached to. So, I am going to write this part a little bit differently. The first thing I am going to do is very similar to the way we access the parameters and that is. I am going to pull off the name of the button. Remember we called that "btnRed." and I am going to use a dot.
Now in this case, I am not going to put a property at the end of it. I am going to put that handler we use before. I am going to use "onRelease". In general syntax rules in a program, I am going to set it equal to a function. All functions have parameters or at least the space to have parameters. So, I am going to put an empty set of parenthesis that open and close, right there.
This is the syntax will use to, I guess you would call it "remotely connect up a button". We are connecting this button off from this key frame instead of connecting it directly to the button itself. Let us try that out. "Ctrl+Enter", now my buttons right there and when I click it. You can see that it is executing my statement properly.
Now, that is well and good but one thing that we are going to be doing is we are going to be moving this script around. Now, you can kind of imaging in a program where you have got lots of button for navigation and other buttons that control all...
click to read more