objects
a central programming theme is the cycle of writing code that makes other code easier to write.
programming languages themselves begin the cycle, offering built-in groupings of basic and
common functionality. these groupings are called objects.
objects are containers for collecting properties and
methods under a common theme.
physical examples
conceptual examples
- point
- movie clip
- game character
flash objects
- Point
- Sprite
- SoundTransform
- Math
objects are commonly named after nouns, to provide insight into the logic behind the properties and methods it collects.
properties
...represent characteristics of an object
- the point's x and y coordinates
- the opacity of a graphic
- the loudness of a sound
- the value of  π
...are commonly named after nouns and begun with lowercase letters
x
alpha
volume
PI —except whent the value will never change; then convention is to use all caps.
methods
...expose actions the object can perform
- drawing a rectangle
- moving some distance
- rounding a floating point number to the nearest integer
- writing a message to the console
...are commonly named after verbs and begun with lowercase letters but have parentheses at the end
drawRect():void
offset():void
round():Number
trace()
parameters
...provide information the method needs to operate
- from where to where?
- how far?
- how high?
- of which numbers?
- what message?
and that's what the parentheses are for—passing parameters into the method.
multiple parameters are separated by commas.
drawRect(20,50, 70,100)
translate(2, 1)
round(5.7)
trace("hello")
but how do we know what order the parameters should be in, or the ranges of acceptable values?
we need to read the documentation, and look at the method
signatures.
drawRect(x:Number, y:Number, width:Number, height:Number):void
offset(dx:Number, dy:Number):void
round(val:Number):Number
trace(message:String):void
parameter order, units and context are all determined by the method (need to read the documentation).
dot syntax
properties and methods of actionscript objects are accessed using the
. (dot,
a.k.a. period) operator
graphics.drawRect(20,50, 70,100)
point.x
point.offset(2, 1)
character.favoriteFood
character.jump(5)
Math.PI
Math.round(5.7)
trace("hello")
scope
when we ‘access’ properties and methods, the word implies
getting into, which is accurate.
program elements in the run-time environment exist in different levels of containment, called
scope .
local
object properties and methods do not exist outside the object
✘ PI
✔ Math.PI
global
built-in objects and some loose methods exist in global scope and are always available.
Math
String
parseInt()
trace()