Hello i have a function as following:
private function seatClickHandler(e:MouseEvent):void{
var check:Check = new Check();
if(e.target.contains(check)){
e.target.removeChild(seat);
}else{
e.target.addChild(check);
}
}
basicly i want to check if e.target contains a child called check. If it does i want e.target to remove the child, else i want to add the child. But the method i tried doesnt seem to work although i think this is the way to go. Any suggestions?
When you declare your Check object, Actionscript creates a reference code for that specific object.
So the first time your code is run, your
Checkobject could be given a reference of@c0ecc29. Yourifstatement checks to see if@c0ecc29is a child component oftarget. It won’t be, so theCheckobject with reference@c0ecc29is added totarget.The second time the
clickHandleris called, a new instance of theCheckobject is created which will have a new reference id. Your target has the original Check object with the@c0ecc29reference so it won’t get removed.The correct way to get this working depends on what target is (DataGrid, Group, etc.).
EDIT:
Based on your comments, I would try something like this. It checks to see if the
Checkobject is a child oftargetand adds it if needed. Then when theCheckobject is clicked, it will toggle its visibility.If you need to actually remove the
Checkobject fromtargetinstead of just changing its visibility, you could try this: