Skip to main content
Participant
March 29, 2020
Question

Need help figuring out this code. ClicktoHide

  • March 29, 2020
  • 1 reply
  • 318 views

I'm working on a code that has a button that reveal a hidden object. Easy right? But I want the hidden object to reveal on a another frame. 

Like Frame 1: Button that reveal hidden object on Frame 2

        Frame 2: The object is revealed cause the button in Frame 1 is pressed

 

Frame 1:

NameOne.addEventListener(MouseEvent.CLICK, f1_ClickToHide);

function f1_ClickToHide(event:MouseEvent):void
{
NameTwo.visible(2) = true;
}


Frame 2:

NameTwo.visible(1) = false;

 

Don't know how that works. I test and get error

    This topic has been closed for replies.

    1 reply

    JoãoCésar17023019
    Community Expert
    Community Expert
    March 29, 2020

    Hi.

     

    In AS3 documents it's not possible to access instances that doesn't exist in the current frame. So you have to create a boolean variable and set it to true when the user presses the button. Then when the user navigates to the frame that contains the hidden instance you set the visibility value of this instance to the variable's value. Like this:

     

    AS3

    Frame 1

    import flash.events.MouseEvent;
    
    var hidden:Boolean = false;
    
    function revealHandler(e:MouseEvent):void
    {
    	hidden = true;
    }
    
    function nextHandler(e:MouseEvent):void
    {
    	nextFrame();
    }
    
    stop();
    yourButton.addEventListener(MouseEvent.CLICK, revealHandler);
    nextButton.addEventListener(MouseEvent.CLICK, nextHandler);

     

    Frame 2:

    hiddenObject.visible = hidden;

     

    I hope this helps.

     

     

    Regards,

    JC 

    Participant
    March 29, 2020

    Oh man. Thank you so much! It really work. I learn something new.

    JoãoCésar17023019
    Community Expert
    Community Expert
    March 29, 2020

    Great! You're welcome!