전에 올린 buttonMode 에 관한 글(http://www.minarto.com/24) 에 몇가지 사실을 더 덧붙일 것이 생겼다.
as3 에서 버튼 이벤트가 걸린 InteractiveObject 위에 InteractiveObject 가 겹쳐 있다면 겹친 부분은 버튼 이벤트가 발생하지 않는다.
var sp1:Sprite = new Sprite();
sp1.graphics.beginFill(0);
sp1.graphics.drawRect(0, 0, 100, 100);
sp1.graphics.endFill();
addChild(sp1);
var sp2:Sprite = new Sprite();
sp2.graphics.beginFill(0xFFCC00);
sp2.graphics.drawRect(0, 0, 100, 100);
sp2.graphics.endFill();
addChild(sp2);
sp2.x = sp1.x + 20;
sp2.y = sp1.y + 20;
sp1.buttonMode = true;
var sp1:Sprite = new Sprite();
sp1.graphics.beginFill(0);
sp1.graphics.drawRect(0, 0, 100, 100);
sp1.graphics.endFill();
addChild(sp1);
var tf:TextField = new TextField();
tf.text = "sdfasfsf";
tf.textColor = 0xFFFFFF;
tf.autoSize = TextFieldAutoSize.LEFT;
tf.selectable = false;
addChild(tf);
tf.x = sp1.x + 20;
tf.y = sp1.y + 20;
sp1.buttonMode = true;
tf.mouseEnabled = false;
이 상황에서는 다시 처음 코드와 같이 MouseEvent.ROLL_OUT 가 발생해버린다.
그럼 어떻게 해결해야 하는 것일까?
이것 저것 생각해보다가 다음과 같은 방법을 쓰게 됐다. 엄밀히 말하면 이건 해결이라기 보다는 우회이다... 바로 비트맵으로 TextField 클래스를 표현하면 된다.
var sp1:Sprite = new Sprite();
sp1.graphics.beginFill(0);
sp1.graphics.drawRect(0, 0, 100, 100);
sp1.graphics.endFill();
addChild(sp1);
var tf:TextField = new TextField();
tf.text = "sdfasfsf";
tf.textColor = 0xFFFFFF;
tf.autoSize = TextFieldAutoSize.LEFT;
tf.selectable = false;
tf.x = sp1.x + 20;
tf.y = sp1.y + 20;
var bd:BitmapData = new BitmapData(tf.width, tf.height, true, 0x00FFFFFF);
bd.draw(tf);
var bm:Bitmap = new Bitmap(bd);
addChild(bm);
bm.x = tf.x;
bm.y = tf.y;
sp1.buttonMode = true;
Tag : as3, buttonMode, mouseEnabled