Consolidating Scripts


You've just learned how to create movie clip instances dynamically. Earlier when we would instantiate clips, we would then attach script to them. We would use an event handler such as enterFrame to activate certain scripts on the instance at certain times. If we create a clip instance dynamically with attachMovie , how can we attach script to it afterward? The answer to this question is a set of function reference properties contained in all movie clips. These references allow us a second way to attach event handlers to an instance. In fact, this form of event handler is more powerful and versatile than the form you saw earlier. This new way of attaching script to dynamic instances is so nice that after we learn it, we'll never want to do it the old way again.

The main reason that these new reference properties are so nice is that they allow us to localize our code. What I mean by this is that from now on, almost every bit of script we write will be attached to frame 1 of the main timeline. No longer will we drag instances from the library to the stage and then add script to the instance. From now on, all our script will exist in one place and one place only: frame 1 of the main timeline.




Macromedia Flash MX 2004 Game Programming
Macromedia Flash MX 2004 Game Programming (Premier Press Game Development)
ISBN: 1592000363
EAN: 2147483647
Year: 2004
Pages: 161

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net