adding event listeners

0 favourites
  • 7 posts
From the Asset Store
Kids Game
$24.50 USD
50% off
New Sounds Added Update: 115 new sound effects added for no additional cost!
  • Just a quick question...

    I haven't been able to make work, or find any reference in the scripting section of the manual to eventListener "beforeunload"

    I'm looking to use it as I'm working on something that needs to do some things before actually closing the app, but triggered BY closing it.

    What's the best approach inside C3's JS implementation?

    Thanks in advance!

  • JavaScript in Construct works the same as JavaScript in a web page. You can write the same code you'd use on a web page. There's nothing special about Construct's "JS implementation" - it's not Construct that implements JS, it's the browser.

    You may have difficulty with some APIs when Construct runs in a web worker, but by default when you add JS code it runs in the DOM, so as long as you don't change the 'Use worker' setting then there's nothing different to coding a web page.

  • Hmm interesting... I was unable to get event listeners like "beforeunload" and "click" to work... I'm sure I'm trying to do them wrong, as this is a JS learning journey for me 100%. My entire knowledge base prior to my current project is Construct Classic, Construct 2, Construct 3 (event sheets only for all) and then 6502 Assembly. So there's definitely a curve lol...

    That said, an example cap for non C3 specific event listeners would be much appreciated by me and maybe others.

  • For context, I'm trying to open and close secondary windows as undockable UI elements of an app I'm working on, that can be moved outside the main window, moved to secondary monitors, etc, that will be auto closed if the main window is closed.

    (I'm also looking for a way to remove the titlebars from the main window and secondary windows as well, given that this is intended as a desktop app first, and web app second)

  • By far the easiest and quickest way to get help is to share a sample project. Otherwise all anyone can do is guess.

  • Fair point!

    https://shorturl.at/rweV2

    So the goal with this test project, was to have the generated noise move from the main window to a popup window, when clicked, then have the popup close when its clicked. Unfortunately, I've only managed to have the popup close when the main window is clicked a second time. I also want to detect when the main window is closed, so it can close the popup at the same time. Eventually this would evolve into saving the coords of the popup so the next time the project is run, it'll open the popup in the same place, etc.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I'm also running into an issue regarding eventListeners in conjunction with the Mouse and Button objects... I've successfully got a toggle button working, that animates based on CSS styling... however, I'm unsure how to add properties like :hover, and :active through setCssStyle(), as I also want a button that only remains down while the mouse button is down.

    I've got my "click" event listener on my button, and my mousedown/mouseup on the runtime, however it seems that click overrides the others, and the others only fire when the mouse cursor is not over a button, is there a way around this?

    Ultiamtely, the desired behaviour is that its clicked, animates being pressed, stays in the down position regardless of mouse cursor location, and then releases when the mouse button is released.

    I had thought it would make sense just to have a string that constantly reports the state of the mouse button, but that seems difficult to achieve here...

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)