Skip to main content
Eager_Hummingbird5C5E
Participant
August 3, 2020
Question

All Mouse over Action completed 1 time randomly to initiate animated screen and reset

  • August 3, 2020
  • 2 replies
  • 367 views

Hello - I'm trying to simulate a game-like interaction using adobe animate action scripts. 
Essentially I'm building a screen where there are 5 shapes (buttons) on the screen, once they are all clicked - in any order the user desires - the screen would go to a keyframe that plays an end-scene animation then reset.

 

I'm only able to get this to work sequentially but need this to work randomly - where the buttons are pressed in no specific order. Does Animate CC support something like this? If this requires a custom script any suggestions for places to look would be appreciated! 

    This topic has been closed for replies.

    2 replies

    JoãoCésar17023019
    Community Expert
    Community Expert
    August 3, 2020

    Hi.

     

    There are several ways to do this kind of interaction. One way is to place all buttons in the same container and then store the ones that have been clicked in an array without allowing duplicates. Then check if the array length is equal to the total of instances in the container.

     

    Assuming that you're working on an HTML5 Canvas document, the code could be something like this:

    var root = this;
    
    root.checkButtons = function(e)
    {
    	if (root.buttons.indexOf(e.target) === -1)
    		root.buttons.push(e.target);
    		
    	if (root.buttons.length === root.container.numChildren)
    		root.gotoAndStop(1);
    };
    
    root.container = this;
    root.buttons = [];
    root.stop();
    root.container.on("click", root.checkButtons);

     

    Please let us know.

     

    Regards,

    JC

    Eager_Hummingbird5C5E
    Participant
    August 3, 2020

    Thanks JC - I'm a bit new to Animate and ActionScripts. Your information seems thorough but I don't know what containers/arrays are or know enough to test the code yet. https://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ee3.html
    This seems in line with what you mentioned (?), I'll probably need to look into more documentations. And I am working in a HTML5 Canvas document.

     

     

     

    Legend
    August 3, 2020

    HTML5 Canvas documents use JavaScript, not ActionScript.

    Legend
    August 3, 2020

    If you already have it working sequentially, what's preventing you from doing it randomly?

    Eager_Hummingbird5C5E
    Participant
    August 3, 2020

    lack of experience with Animate? 🙂 It seems doable but I'm stuck at how to set up an animation that plays when each button has been moused over once.