Learn about creating a placeholder for multiple objects in this Flash Professional 8 advanced next level training video series.


More DIY videos at 5min.com

Video Transcription

Now our next procedure is to take what we have built for one photo, and expand this out, so that we could do it for multiple photos, and I need to do a couple of things to get this going. The first one is to make sure that I am not explicitly dealing with one instance of the movie clip. I have got to vary this so that I can make several instances, each with their own unique identifier name, and their own unique depth level. But very importantly, we have got an issue of sequence here. You can see here pretty easily that I have to have the flyer1 instance existing on the screen before my onEnterFrame value will work with it. Now I don't want to build an onEnterFrame value for every single photo, one at a time, copying and pasting this all the way down. So we need to build our script into something that is general and repeatable. That means taking out all of our explicit references, and it also means we might need to take advantage of couple of placeholder objects in our script, and that is where we are going to start. We are going to create an object that we are going to use as placeholder for all of the different flyer objects that we are going to be making later on. I am going to go up to the top of the script and I am going to instantiate that object. I will just add a line underneath our photoScale here, and I will create an object called flyerInit. I am going to use the var keyword to localize it to this timeline, and I am also going to type this as an Object. var photoScale = 30; var flyerInit: Object This is a common way to generalize our script. The reason I chose the Object class, is that it is a very generic class. It really doesn't have a lot of its own properties and methods. It's also what we are going to call a Dynamic class, and what that means is that we can add properties and methods to it, even after we have instantiated the object. Now I will finish off my instantiation by using the New keyword. Of course, this is going to be an object, so I use the object constructor, and we will have an object called flyerInit. var photoScale = 30; var flyerInit: Object = new Object (); Now, the reason we can take advantage of this so easily is that our attachMovie method has an optional property that allows us to identify what you might call a Template object. Now I am just going to click my cursor right inside of the attachMovie parameters. I will use this little button here to show the code hint that will force our hint system to bring this back up again. This is what I am talking about at the end, the Init object. Now what I am going to do is I am going to add our flyerInit as the last parameter. That will use our flyerInit object as a template, and everything our flyerInit objects has in the way of methods and properties and event handlers, will be inherited by our new movie flyer1. this.attachMovie ("p1","flyer1", 1, flyerInit); Now just to show how this is going to work, I am going to change our onEnterFrame from flyer1 to flyerInit. FlyerInit.on EnterFrame = function () { Now, with that change, if we test our movie as is, I will just do a Ctrl+Enter or Command+Enter on the Mac, you can see that we lost all that EnterFrame animation and the action going on there, and that is specifically because of a sequencing problem. We are assigning flyerInit; let me go up here just a little bit, we are assigning flyerInit as a template object to our new attachMovie command, before we actually built the onEnterFrame. So, in this type of the sequence and in any sequence, I will need to make sure that the object is setup and defined before I use it. this.attachMovie ("p1", "flyer1",1,flyerInit); Now, we can fix that pretty easily. I will just select everything down here at the bottom. Now that's my entire onEnterFrame function and I will just cut it out of the bottom, and will paste it up to the top of our script. Now it doesn't matter too much where you put this but that sequence is in order. We will need to make sure it is after we initialize the object and before we use the object. So I will go right down underneath our randomized function and I will edit it there. We will just make an extra line, paste it in, and if we test our movie again, we should see that we have got that moving it back.