Custom Variable Objects

I l @ ve RuBoard

When working with movie clip screen positions , you always have two components : x and y. Wouldn't it be nice to be able to organize them a little better? For instance, you could name your variables positionX and positionY instead of just x and y .

But these are still just totally different variables. The names just look similar.

You can use custom variable objects to better organize your variables. For instance, you could store the x and y position of your movie clip like this:

 pos = {x:10, y:20}; 

By using the curly brackets, you are creating an object. In this case, the object has two parts : x and y , with values 10 and 20. You can access the parts like this:

 trace(pos.x); 

You can also modify the parts with operators and such, just like a normal variable. In this example, you would just use pos.x instead of x .

Imagine a more complex structure such as a record in a database. The object could be record , and the properties of it could be things such as name , address , phone , and so on. You would access them with syntax like pos.name .

You can create an object gradually, placing new properties in it as you need them. Here is an example:

 record = new Object(); record.name = "Gary"; record.age = 32; record.state = "Colorado"; trace(record.name); 

In addition to making data easier to organize, custom objects are similar to built-in Flash objects. Two examples of built-in objects are the Color object and the Date object.

I l @ ve RuBoard


Sams Teach Yourself Flash MX ActionScript in 24 Hours
Sams Teach Yourself Flash MX ActionScript in 24 Hours
ISBN: 0672323850
EAN: 2147483647
Year: 2002
Pages: 272

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