这两个家伙有关系么?

当然有,而且还挺紧密的。

它们之间的关系就是:

如果一个Sprite不开启buttonMode,那么就不会有FocusEvent事件发出

当然,TextField虽然没有buttonMode,也会有FocusEvent。

那么SimpleButton会如何?我没试,懒得试了……

把下面的代码中的 _sprite.buttonMode = true; 一行注释掉,可以看到(或者说看不到?)效果。

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.FocusEvent;
import flash.events.MouseEvent;
import flash.text.TextField;
public class Focus extends Sprite
{
public function Focus()
{
getSprite();
getSprite(200, 0);
var _tf:TextField = new TextField();
_tf.type = 'input';
_tf.border = true;
_tf.x = 200;
_tf.y = 200;
_tf.addEventListener(FocusEvent.FOCUS_IN, handler_focusin);
_tf.addEventListener(FocusEvent.FOCUS_OUT, handler_focusout);
addChild(_tf);
}
private var _sprite:Sprite;
private function getSprite($x:int=0, $y:int=0):Sprite
{
var _sprite:Sprite = new Sprite();
_sprite.graphics.beginFill(0);
_sprite.graphics.drawRect(0,0,100,100);
_sprite.graphics.endFill();
_sprite.x = $x;
_sprite.y = $y;
_sprite.useHandCursor = true;
_sprite.buttonMode = true;
this.addChild(_sprite);
_sprite.addEventListener(FocusEvent.FOCUS_OUT, handler_focusout);
_sprite.addEventListener(FocusEvent.FOCUS_IN, handler_focusin);
_sprite.addEventListener(MouseEvent.CLICK, handler_click);
return _sprite;
}
private function handler_focusout(evt:FocusEvent):void
{
trace('focusout,target:', evt.target, ',relatedTarget:', evt.relatedObject);
}
private function handler_focusin(evt:FocusEvent):void
{
trace('focusin,target:', evt.target, ',relatedTarget:', evt.relatedObject);
}
private function handler_click(evt:MouseEvent):void
{
trace('click');
}
}
}

留言

2011-06-27
次访问