Skip to main content
Participating Frequently
February 26, 2021
Answered

Using Buttons to change other objects' images

  • February 26, 2021
  • 1 reply
  • 683 views

Hello, I'm attempting to put together a small animate project for my finals in college, and I've run into a massive roadblock with one specific function.

I want to be able to have a button's graphic change based on a button press.

The current system is as stands: In frame 0 there is the title, the instructions, and four buttons, three of which bring up additional content. All three of these will present the user with choices, where when you choose any of them, or the main menu button, it returns you to frame 0. However, I want the choices you have (AKA the buttons attached to those choices) to change the image of the button you originally pressed.

IE: >Click WorldChoiceButton; >Opens Menu; >Click PeacefulButton; >Changes image under WorldChoiceButton's frame to Peaceful.jpg

but I can't figure out what to do here to make this work. At first, I wanted to try changing the whole symbol used for the Buttons entirely, but then I decided to leave the button as a frame, with transparency in the middle, and place a Graphic symbol in the transparent space, and try using actions within the symbol to change the frame based on a global variable. Issue is, I don't know how to call on global variables in the script in Animate, and I everything I've attempted has caused some fatal error in the html code and it won't display in-browser as long as the code remains in place.

    This topic has been closed for replies.
    Correct answer kglad

    Sorry for the delay, another final took priority for the moment. I'm now back to working on the issue, and any attempts to call the variables in actions isn't working.

    I've tried multiple versions of this code, ranging from attempting

    mc.[MovieClipName].gotoAndStop([FrameName]);
    to
    _this.gotoAndStop(mc.[FrameName]);
    And nothing has yielded results in changing the active frame in the movieclip. Am I simply coding it wrong or would I need to put it in a separate check than the _this.gotoAndStop(0); action under the check for _this.[Button].on('click', function(){})?


    you're coding it wrong.

     

    but i'm not sure what the correct coding should be because i don't know the timeline containing the code and i don't know what you're trying to reference with code.

     

    but if you're trying to direct moveiclip mc (that's on the timeline with the code) and you're trying to direct it to a frame (label or number) stored in FrameName and FrameName is defined on mc's timeline, use:

     

    this.mc.gotoAndStop(this.mc.FrameName);

    1 reply

    kglad
    Community Expert
    Community Expert
    February 27, 2021

    html5/canvas or as3?

    Participating Frequently
    February 27, 2021

    Html5

    kglad
    Community Expert
    Community Expert
    February 27, 2021

    use movieclip buttons and put the images you want to use on the various movieclip buttons' timeline (with a this.stop() in the first frame).  you can then use code to determine which frame to display on each moveiclip button timeline.