- Creating Sliding Panels for Navigation and Transition Effects
- Other Uses of the Slide Algorithm
- Multiple Mouse Slide
- Coding the Multiple Movement Algorithm
- Using Functions to Make Efficient Code
- Passing Parameters to Functions
- Duplicating the Movie Clip On-the-Fly
- Adding Scale to the Effect
- The Sliding Mask Transition Effect
- Creating the Function for X and Y Movement
- Adding to the Transition Effect
- Conclusion
Using Functions to Make Efficient Code
Functions are self-contained bits of code that are executed or "called" when you need to use them. The best way to describe it is to give you an example. Say, for example, you have a button that, when it's clicked, will increase the scale of myClip in the X and Y axes. You could write the following code:
on (release) { myClip._xscale = myClip._xscale + 10; myClip._yscale = myClip._yscale + 10; }
This would, of course, work fine. But what if you needed to do this on several buttons? Writing the same two lines would be a pain. Instead, you can define a function in the first frame of the main timeline as follows:
function increaseScale() { myClip._xscale = myClip._xscale + 10; myClip._yscale = myClip._yscale + 10; };
Now whenever you want to increase the scale of the movie clip with the button, you can simply write the following code:
on (release) { _root.increaseScale() }
This will have exactly the same effect, but it's much more efficient. It also means that if you wanted to amend the codeto decrease the alpha as well as the scale, for exampleyou could just add it to the function. Before I would have had to go into every single button and alter each piece of code.