Skip to main content
Known Participant
March 12, 2014
Answered

Can't add event listener to instantiated Movie Clip

  • March 12, 2014
  • 1 reply
  • 762 views

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

This topic has been closed for replies.
Correct answer kglad

change:

function newLayerBT_CLICK(MouseEvent):void{

to:

function newLayerBT_CLICK(e:MouseEvent):void{

1 reply

kglad
Community Expert
Community Expert
March 12, 2014

copy and paste your error message.

RxMadjackAuthor
Known Participant
March 12, 2014

ReferenceError: Error #1069: Property CLICK not found on flash.events.MouseEvent and there is no default value.

          at FlashCCSim_fla::timelineToolbar_6/newLayerBT_CLICK()

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
March 12, 2014

change:

function newLayerBT_CLICK(MouseEvent):void{

to:

function newLayerBT_CLICK(e:MouseEvent):void{