Tutorials, extensions, and source files for ActionScript, Flash, and other Adobe products.

 

senocular.com ActionScript Library

Flash5buttonActions.as

Name: MC button actions [F5] - add button actions to a Flash 5 movieclip
Author: senocular: www.senocular.com
Date: 1899-12-31T00:58:53.100
Documentation:
MovieClip: Button actions recognized by a Flash 5 movieclip

- code to be placed on the moveiclip itself for it to react to button-like events.

Note:
- designed for flash 5 (mimics similar MX behaviors)
- movieclips will not gain a finger cursor using this method
- unlike buttons, these actions can be 'seen' through other movieclips having them.  Buttons,
for exmple, if placed over top of each other, the highest button gains precedence and cancels
the actions of those below it.  This is not the case with this code

Example:
// make a movieclip in _root named ball, place the above cod on it, then in a frame
// on _root, put the following to make that moveiclip recognize & show the button actions:

ball.onDragOut = function(){
	trace("dragOut")
}
ball.onDragOver = function(){
	trace("dragOver")
}
ball.onRollOut = function(){
	trace("rollOut")
}
ball.onRollOver = function(){
	trace("rollOver")
}
ball.onPress = function(){
	trace("press")
}
ball.onRelease = function(){
	trace("release")
}
ball.onReleaseOutside = function(){
	trace("releaseOutside")
}
ball.onKeyPressa = function(){
	trace("pressed a")
}
ball.onKeyPress1 = function(){
	trace("pressed 1")
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// code placed ON the movieclip to recognize button commands
onClipEvent(load){
	pressed = false;
	IsOver = function(){
		return this.hitTest(_root._xmouse, _root._ymouse,true);
	}
	over = IsOver();
}
onClipEvent(mouseMove){
	if (over ^ IsOver()){
		if(over){ if(!pressed) this.onRollOut();
			else this.onDragOut();
		}else{ if(!pressed) this.onRollOver();
			else this.onDragOver();
		}
	}
	over = IsOver();
	updateAfterEvent();
}
onClipEvent(enterFrame){
	over = IsOver();
}
onClipEvent(mouseDown){
	if (over){
		this.onPress();
		pressed = true;
	}
}
onClipEvent(mouseUp){
	if (pressed){
		if (over) this.onRelease();
		else this.onReleaseOutside();
		pressed = false;
	}
}
onClipEvent(keyDown){
	this["onKeyPress"+String.fromCharCode(Key.getAscii())]();
}