Main Content
Refering to symbols
In ActionScript, you constantly want to refer other objects. Here are some of the times you may want to do this:
- Duplicating Movie Clips : choosing the Movie Clip to duplication
- Accessing other variables : Score - "how many points does the player have?"
- Hit Testing : Am I hitting that other symbol?
Suppose we want to set a nearby turrets _rotation property to 180, as an example. Then we will need to use a path like that to finishing off the line of code (with a relative value). Relative means "from the point of view of the object we are using" and whereas absolute means "from the point of view of the _root, the root of everything". Normally it doesn't matter which you use, but relative is good where things might change.
Type " = 180;". Now go to the beginning of that line, and look above you on the actions panel. You should see a toolbar that looks a little like this (without the red blob):
The red blob shows you the button we need - it looks like a gun scope. Click on it. This is the window we get:
This uses the instance name of an object - it will prompt you if you haven't set one. Those with brackets do not have instance names. We want the turret, so select "relative" and press "ok". This leaves you with the answer
Answer: this._parent.turret = 180;
Well there you are! Hope you understand a bit better now.
Harry.