Skip to main content
Participating Frequently
October 16, 2022
Question

Why am I getting the error "event.addEventListener is not a function"?

  • October 16, 2022
  • 3 replies
  • 423 views

This is my code in actions for Adobe Animate. There is a symbol instance called container.

var root = this;
var container;

function main()
{
root.stop();
container = root.container;
container.mouseChildren = true;
container.hitArea = new createjs.Shape(new createjs.Graphics().f("#000").dr(0,0,960,540));
container.cache(0,0,960,540);
stage.addChild(container);
container.on("mousedown", mousePressed);
createjs.Ticker.addEventListener("tick", stage);
var drawing = new createjs.Shape();
container.addChild(drawing);
}

 

var lastPoint = new createjs.Point();

function mousePressed(event)
{

lastPoint.x = event.stageX;
lastPoint.y = event.stageY;

event.addEventListener("mousemove", function(event){

drawing.graphics.ss(20, "round").s("#ff0000");
drawing.graphics.mt(lastPoint.x, lastPoint.y);
drawing.graphics.lt(event.stageX, event.stageY);

lastPoint.x = event.stageX;
lastPoint.y = event.stageY;

var erase = document.getElementById("toggle").checked;
container.updateCache(erase?"destination-out":"source-over");
drawing.graphics.clear();
});
};

 

main();

    This topic has been closed for replies.

    3 replies

    Dr Abstract
    Known Participant
    October 16, 2022

    Hi JZ - perhaps you want to put the addEventListener() on the event.target?  I did not really read the rest as to figure out what you are doing but event.target will be what caused the event.

    Dr Abstract
    Known Participant
    October 16, 2022

    Wow, you guys are fast here... I did not see the other responses.  Cheers.

    kglad
    Community Expert
    Community Expert
    October 16, 2022

    learn how to debug your errors.  you'll make more (if you're like me), 

     https://youtu.be/KJEl0OenGUY

    kglad
    Community Expert
    Community Expert
    October 16, 2022

    what's event.addEventListener supposed to be?  event.currenTarget.addEventListener?

     

    and, in the future, and for others, check the line number with the error so you can pinpoint and correct your own errors more quickly

     

     

    JoãoCésar17023019
    Community Expert
    Community Expert
    October 16, 2022

    Hi.

     

    The event object contains information about the event but it is not an event dispatcher.

     

    Maybe what you want is event.currentTarget.addEventListener or event.target.addEventListener.

     

    Please let us know.

     

    Regards,

    JC