Object's click event

The object state code written in Action Script cannot be used in the click event of the object in the scene.
Do you have any solution suggestions for this?


I was trying to recreate your scenario but need more detail.

I have created an object on the stage with two states. I then made an advanced action to change the state of the object by clicking on the object itself. It worked.
I then used JavaScript to change the state of the object by clicking on itself and it worked.

Can you provide some more detail on what you are trying to accomplish and how it is to be realized?


Thank you for the additional detail. It was indeed helpful to see the scope of the project.
This is a great interaction to help visualize the circuit. I believe I have recreated what you are trying to do.


What makes this tricky is that there is a great deal of conditional logic involved.

I admit that I first tried to do this with only actions and became frustrated when I struggled to find a way to perform an action based on multiple conditions and to also perform multiple actions based on multiple conditions. I then moved to JavaScript which made a couple things much easier. As it stands there are still some flaws in this setup.

One aspect that could have made this interaction perfect is the ability to configure different actions for different objects that are accepted. I would like to have made a different action for each of the three batteries but I didn’t see a way to do that.

If there is a way to do that - I would love to know it.

Here is what I did to make this happen.

  1. I am using two variables power and voltage
  2. Power variable tracks the power as “on” or “off”. I also toggle the state of the image to show the handle in the up or down position.
  3. Voltage variable tracks the voltage of the battery that is selected. This is done with an onDragStart action. (This is where separate accept actions would be nice so that onAccept the variable changes.)
  4. I am using 4 states for each of the two light bulbs. off, low, medium, and high. Off is the default.
  5. The JavaScript just checks to see if both power is “on” and voltage is NOT equal to 0. If both of these are true - we check the voltage value and change the state of the lights accordingly. Otherwise if both are not true, we change the state of the lights to off.

The flaw in this comes in when the learner begins dragging the battery which sets the voltage value. If they drop the battery before reaching the drop target and it returns to the beginning - the value is still set and the learner could toggle the switch and see the lights go off and on without a battery in place. A second flaw is that if you drag the battery fully through the drop zone - the voltage variable is wiped out.

Here is the code I used to do this - I realize that it may not be what you’re looking for but maybe it will help somehow. The staff are pretty amazing and they may have a better solution to this.


window.checkLights = function() {
    if ((prez.variable("power")=="on") && (prez.variable("voltage")!=0)) {
        if (prez.variable("voltage")==1) {
        if (prez.variable("voltage")==3) {
        if (prez.variable("voltage")==9) {
    else {

Drop Target onAccept


switch onClick

if (prez.variable("power") == "off") {

else {

Adjust variable -voltage- to value of 1, 3, or 9 accordingly.

I hope this is useful in some way.


Congratulations. It was very well prepared.

This is exactly what I want. Could you send me the project file of your work so that I can transfer the codes to my own project?

Sure - just be careful to change object names and such as mine would have been different.
circuit.approj (484 KB)


Hi @gregs,

Your creative ideas and insights have inspired and guided many within our community. Thanks to your contributions, our community is more vibrant, and countless users found solutions to their challenges.

We are truly fortunate to have you as an active member :tada:.

Once again, thank you for being such an integral part of our community. We look forward to continuing our journey together, creating a space where creativity and support develop.

Warm regards,

1 Like

Hi @gregs

I have adjusted a bit to fix two flaws on your project.
circuit_edited.approj (436 KB)

Hope it helps,


Thanks, @Hoanp

I see what you did there. I was looking in the wrong place.

I was thinking there might be a button here to do an action for each accepted source.
You all are rock stars!

1 Like

Thanks for your help.

Hi @cemileyavuz and @gregs, I have another way to do it without using code, hope it can help you.
The Circuit.approj (760 KB)

1 Like

Thank you for working on this @Li_Shimin - It is often nice to have multiple options when working through projects.