Skip to main content
Participating Frequently
Oct 16, 2022 1:54 PM UTC
Question

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

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 is closed to new replies. Start a new post to keep the conversation going.

    5 replies

    Dr Abstract
    Known Participant
    Oct 16, 2022 2:00 PM UTC

    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.

    Translate
    Dr Abstract
    Known Participant
    Oct 16, 2022 2:01 PM UTC

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

    Translate
    kglad
    Community Expert
    Community Expert
    Oct 16, 2022 2:07 PM UTC

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

     https://youtu.be/KJEl0OenGUY

    Translate
    kglad
    Community Expert
    Community Expert
    Oct 16, 2022 2:00 PM UTC

    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

     

     

    Translate
    JoãoCésar17023019
    Community Expert
    Community Expert
    Oct 16, 2022 2:00 PM UTC

    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

    Translate