
Page 2 of 2
Jesse Stratford
Jesse lives and works in Melbourne Australia. He is the Cofounder and a Director of http://ActionScript.org. A Flash enthusiast, teacher, author, freelancer and speaker Jesse enjoys participating in the http://ActionScript.org community and the wider Flash scene when he has time.
View all articles by Jesse StratfordThis table outlines the code you can substitute in for the property attribute, and what it will get you.
| setProperty ( target, _x , value); | The X axis position (in pixels) of the target clip. value should be a number; no quotes! |
| setProperty ( target, _y , value); | The Y axis position (in pixels) of the target clip. value should be a number; no quotes! |
| setProperty ( target, _width, value); | The width (in pixels) of the target clip. value should be a number; no quotes! |
| setProperty ( target, _height, value); | The height (in pixels) of the target clip. value should be a number; no quotes! |
| setProperty ( target, _rotation, value); | The rotation angle (in degrees, -360 through 360) of the target clip. value should be a number; no quotes! |
| setProperty ( target, _name, value); | The instance name of the target clip. |
| setProperty ( target, _xscale, value); | The X scale proportion relative to the original clip size, (in percent) of the target clip. value should be a number; no quotes! |
| setProperty ( target, _yscale, value); | The Y scale proportion relative to the original clip size, (in percent) of the target clip. value should be a number; no quotes! |
| setProperty ( target, _alpha, value); | The alpha fade level (in percent) of the target clip. value should be a number; no quotes! |
| setProperty ( target, _visible, value); | The visibility status (true (1) or false (0)) of the target clip. |
If you open up the example clip above and view the source on each button you will see it is something like this:
on (release) {
setProperty ("_level0.mouse", _x, xpos);
}
Ignoring the button part of this (the 'on' command) the important line is the second line which gives an example of the usage of Set Property. _level0.mouse is the full path to my mouse movie clip (which I named 'mouse' using the Instance inspector) and is enclosed in quotes because it's a path to a target. _x means I'm wanting to set the X position of the object. xpos is a variable (which the user enters in the text field next to the button). Note that xpos has no quotes around it because I want to set the property to the value within the xpos variable (in this case, the text field).
Finally, Flash 5 (and above) supports infix Set Property notation. The benefit of this is that it is shorter to code and easier to read most of the time. When using infix notation you simply enter the path to the object followed by a dot and then the property you wish to examine (read the paths tutorial if you're lost). So if I want to set the width of a clip with instance name "John" on the main timeline (_root) to 100 pixels I can enter:
setProperty ( "_root.John", _width, 100);
// OR I could use just
_root.John._width = 100;
The same goes with all properties noted in the above table. It is a good idea to become familiar with the infix notation for Set Property as it is more in keeping with the structure of Flash 5 code. Note that this method is NOT compatible with Flash 4, so if you have Flash 4, or wish to publish for Flash 4 compatibility, stick to the old method.
That's it really. Once you get into interactive environments such as games and navigations, you wont be able to live without Set Property! If you have questions, please post them on the forums rather than emailing me directly.
| Jesse Stratford is the Co-Master of ActionScript.org and a freelance Flash developer and teacher. He is based in Australia and enjoys all things Flash. NB: If you have comments or feedback please feel free to email me, but please do not email me Flash questions; the forums are provided for that purpose and you will get a faster answer by posting you question there. |
If you have found this tutorial helpful, I hope that you will take 30 seconds to visit The Hunger Site where, with just one click you can make a free donation of food to a starving person in a third-world country. We do not benefit financially from this action; it is purely an act of charity. |
| This tutorial is protected by International Intellectual Property Rights laws and may not be reproduced or redistributed in full or part, without the prior written consent of the author. Unauthorized reproduction of this tutorial or its contents may result in prosecution. I've worked hard on this tutorial, please don't steal it. |


