COMP126A - University of Waikatomhall/126/Lecture5_handouts.pdf3 Event Handlers An event handler is...
Transcript of COMP126A - University of Waikatomhall/126/Lecture5_handouts.pdf3 Event Handlers An event handler is...
1
COMP126A
Lecture 5: Action ScriptEvents and Properties
Items
Progress with labs Should have finished assignment 1 Hand out Practical 7 and 8
Action Script Events and Properties
2
Demonstrations
http://home.scarlet.be/~bbonte/bonteroom.html
Events
Event: Whenever something happens. Eg: User presses a mouse button press, release, releaseOutside, rollOver, ...
Many events occur. A detailed response toeach provides the richness of moderncomputer interfaces (and excellent Flashweb pages)
3
Event Handlers
An event handler is some ActionScriptinstructions to provide a response to anevent.
In a button on (release) { . . . . . . . }
A movie clip can also respond to events onClipEvent (mouseUp) { . . . . . . . . }
Commands
Setting properties Built-in properties all start with the “_” character property = expression ;
_x = _x + 5 ;
_xscale = 200.0 ;
Symbols (movie clips) have properties See lab handout for a list of interesting ones
4
Getting at properties
In a movie clip event handler we just usethe property name to refer to a property ofthat clip instance: _x
We can also use: this._x ‘this’ means the current movie clip, or
whatever we are coding in at the time The style symbol._x is always a way of
getting at a property
Getting at properties
Symbols can be given ‘instance’ names With instance name ‘StarOne’
we can write StarOne._x The special name _root means the
timeline for our current movie. Objects onthe stage are owned by the timeline
We can write _root.StarOne._x
5
Adding Properties to Instances
We can add our own properties (variables)to named instances Eg. StarOne.direction = 1; For example, could be used to record the initial
state of a clip this.startx = this._x;