• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 7. The Movie Clip Object > Variables in Clips (or “Homemade Properties”...

Variables in Clips (or “Homemade Properties”)

If you understand how the built-in properties of clips can be ascertained and often changed through the dot syntax (object-dot-property), you’ll have no problem understanding how to reference the variables you create in clips. Actually, you should think of homemade variables (in clips) as homemade properties of those clips. Not only is the syntax similar (object-dot-variable), but variables are conceptually the same as properties. Built-in properties include _x and _alpha. If you use a variable inside a clip, say age, you can think of the age property of that clip. Of course, you could say this.box.age=21 in the same way that you could say this.box._alpha=50. There are slight differences with variables (oh, I mean “homemade properties”) in that all can be both seen and changed (unlike properties, some of which can only be seen and not changed). In addition, you shouldn’t name your variables with an underscore. Finally, another difference is that only built-in properties cause an immediate and obvious visual change. If your clip’s “age” variable is higher or lower, you won’t “see” anything unless you write a statement that affects a built-in property. Perhaps use clip._alpha=100-clip.age and then if the clip is older (its age is a higher number), it will be more transparent.

Variables exist inside clips as soon as you start using them. If you had the script this.age=1; on the first keyframe inside a clip, every instance of that clip would have its own “age.” This is identical to how every clip has its own _alpha (and every other property). You have to create and maintain the custom variables, whereas properties are built-in, but the concept is the same. Suppose, for example, that you had two instances of this clip (with the this.age=1 script in frame 1). From the main timeline, if you name one instance “brother” and the other “sister” and then select Debug Movie, you would be able to see each clip’s variables (see Figure 7.3). Back on the main timeline, you can place a button that includes the script _this.sister.age=12 (within a mouse event, of course)—and then perhaps another button with this.brother.age=this.sister.age-2. Notice that both are statements that assign a value to the age variable unique to one clip. The second example assigns brother’s age to the result of the expression this.sister.age-2 (or two less than sister’s age). These examples don’t have an immediate and clear practical use, but they serve to show how you can treat custom variables just like properties.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint