Object Properties
Top  Previous  Next


Description
This is a step-by-step tutorial demonstrating how to manipulate the properties of Text Objects.

Aim
This tutorial uses multiple Text Objects with Input and Dynamic text properties and introduces the Object properties:
_X, _Y
_xscale, _yscale
_width, _height
_alpha
_rotation
_name
_visible.

It also uses the on(press) Button Event developed in the previous tutorial.

.swi file
"properties.swi"


1.Load file "button1.swi". Create an Input Text Object called Xin. (See previous tutorial for more detail). Save the file as "myproperties.swi".  
scripttute6_1

Select the right-justified text option.  

2.Create similar Text Objects called Yin, xscalein, yscalein, alphain, rotationin, visiblein. You can create the new Objects using the Text Tool, or by copying and pasting the Xin Text Object and renaming it  
scripttute6_2

3.Add static text titles for the input boxes and re-arrange as shown below. You may find this easier if you enable Snap To Grid  
scripttute6_3

4.Add Dynamic Text Objects heightout, widthout and nameout. Add corresponding static text titles for the new fields.  

scripttute6_4
5.Use the Autoshape Tool to draw an arrow autoshape-arrowi as shown below. You may have to position the mouse over the autoi Autoshape icon in the Toolbar and hold the left mouse button to see the selection Menu that allows selection of the arrow shape autoshape-arrowi. Name the object "arrow" and tick the 'Target' checkbox.  

Note: After naming the Object, you will have to move away from the 'Name:' field to allow the 'Target' checkbox to appear. The Object MUST be named and have its 'Target' checkbox ticked for it to become a Scripting Object

scripttute6_5


6.Select the arrow shape in the 'Outline' Panel and select the Script tab to add an onLoad() Event Handling function for the arrow. This function will be used to initialise the Input and Dynamic text values  

scripttute6_6


7.Add a name=expr; type statement to the onLoad() Event function.  
scripttute6_7


For the 'Target:' parameter, select _parent.Xin from the pull-down list.  
For the 'Name:' parameter, select Text | text from the pull-down list.  
Leave the operator as =.  
Enter the formula _X. This formula or value can also be entered by right clicking in the formula field then selecting the properties Menu item.  
scripttute6_8

The resulting function should look like this:  
scripttute6_9


8.In a similar way, expand the onLoad function so that it contains the following statements:  
 
_parent.Xin.text = _X;  
_parent.Yin.text = _Y;  
_parent.xscalein.text = _xscale;  
_parent.yscalein.text = _yscale;  
_parent.alphain.text = _alpha;  
_parent.rotationin.text = _rotation;  
_parent.visiblein.text = _visible;  
_parent.heightout.text = _height;  
_parent.widthout.text = _width;  
_parent.nameout.text = _name;  

Note:
You may find it easier to enter one of the statements and then use Copy and Paste to expand that to multiple statements. After entering the multiple statements, edit each individual statement to contain the required data

When the function is executed, the arrow properties will be assigned to the text property of the Input and Dynamic Text Objects  

10.   Add the following statements to the on (press) Event Handling function of the 'b1' button:
 
arrow._X = Xin.text;  
arrow._Y = Yin.text;  
arrow._xscale = xscalein.text;  
arrow._yscale = yscalein.text;  
arrow._rotation = rotationin.text;  
arrow._alpha = alphain.text;  
arrow._visible = visiblein.text;  
 
Do this by selecting the 'b1' button in the 'Outline' Panel.  
 
The on (press) function should appear as shown:  


scripttute6_10

When this function is executed, the arrow properties will be updated with new values obtained from the text property of the various input Text Objects  

11.Select the 'Layout' tab and press the 'Play' button. The initial properties of the arrow Object should be displayed.  
scripttute6_11
Note: The values you achieve for X, Y, height and width may be different depending on where and how large you drew the arrow

It is possible to alter the X, Y, xscale, yscale, rotation and visible settings. If you modify those settings while the movie is playing then press the "=" button, the arrow with the revised settings will be displayed.  

scripttute6_12

Note: If you modify the "visible" property to "0" (zero) it will hide the Arrow.


Analysis
This example demonstrates the various properties that are associated with a Scripting Object.

The arrow onLoad() Event Handling function is used to load the Input and Dynamic Text Objects with the initial properties of the arrow Object. The arrow properties _X, _Y, _xscale, _yscale, _alpha, _rotation and _visible may be altered by modifying the appropriate Input Text Object and then clicking on the button. The button on (press) Event Handling function is used to copy the revised property settings from the Input Text Objects to the arrow Object.

Note:
Altering the _xscale and _yscale properties will cause the _height and _width properties to change. The tutorial example will not display this change as the _height and _width properties are only read when the arrow is initially loaded