Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Can't add event listener to instantiated Movie Clip

New Here ,
Mar 12, 2014 Mar 12, 2014

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

TOPICS
ActionScript
715
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 12, 2014 Mar 12, 2014

change:

function newLayerBT_CLICK(MouseEvent):void{

to:

function newLayerBT_CLICK(e:MouseEvent):void{

Translate
Community Expert ,
Mar 12, 2014 Mar 12, 2014

copy and paste your error message.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 12, 2014 Mar 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()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 12, 2014 Mar 12, 2014

change:

function newLayerBT_CLICK(MouseEvent):void{

to:

function newLayerBT_CLICK(e:MouseEvent):void{

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 12, 2014 Mar 12, 2014

Wow, yea that fixed it.... didn't think I had to include that unless I was going to access the target being passed.  Thank you very much.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 12, 2014 Mar 12, 2014
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines