Can't add event listener to instantiated Movie Clip
Hi guys,
I have a movie clip that I am dynamically loading into my scene when a button is pressed. I then want to add a mouse event listener to the Movie Clip object so it can trigger a function when clicked. I get an error when trying to do this and cannot find a solution anywhere.
Here is my code:
newLayerBT.addEventListener(MouseEvent.CLICK, newLayerBT_CLICK);
function newLayerBT_CLICK(MouseEvent):void{
layerCount = layerCount + 1;
//Make a new object from my BlankLayerMC class
var newLayer:BlankLayerMC = new BlankLayerMC;
addChild(newLayer);
//position the new object
newLayer.y = prevY + newLayer.height;
//Edit text inside object to reflect current layerCount
newLayer.layerName.text = "Layer " + layerCount;
newLayer.layerNum = layerCount;
prevY = newLayer.y;
//My problem occurs with this line....
newLayer.addEventListener(MouseEvent.CLICK, moveSelection);
layerArray.push(newLayer);
}
function moveSelection(e:MouseEvent):void{
var t = e.target;
layerSelectedGraphic.x = t.x;
layerSelectedGraphic.y = t.y;
}
Any help would be greatly appreciated
