Templating across Multiple Projects in Flash

When you want to create a Flash website, there usually is no problem with maintaining consistency. That's because you will typically have a layer on which graphics that are supposed to be the same on each page reside. Well, in some cases one element has to appear on many different layers and frames in one project, then the element should be kept in a symbol so that any changes are reflected in all instances of this symbol.

But what to do when you have more than one project? Projects cannot share their symbols, after all.

The answer is, and 99% of you know it, loadMovie() function. Yes, it alone is a great tool for templating, however it wasn't until recently that I found how powerful it really is. For some of you it might not come out as a shock but it's actually possible to pass arguments to a loaded SWF.

What do I mean? Suppose you have SWF file A and B. In A, you've got a textfield and this code:

someVar = "1234";
loadMovie("load.swf",loadedmc);

While in B, there is:

myTxtField.text = someVar;

 

This won't work, unfortunately. The problem is with how we reference the variable. someVar is referencing only the SWF file it is inside - even though the SWF is a symbol from A point of view!

The trick here is to use _parent or _root with someVar. In this way, we are telling Flash to grab the value of someVar from SWF A.

To understand how helpful this trick can be, consider this situation: you've got a Flash game website with about 30 games. For whatever reason, you want each and every one of them to have the same style of title - font, size, color, background. So basically everything you want to change is what the title says. To achieve this effect, you would have to do steps analogical to those above.

 

OK, I hope you enjoyed this tutorial. Thanks for reading.

Average: 2 (4 votes)