user1133181
user1133181

Reputation: 25

How to make items invisible in actionscript

This may sound like a simple question which I'm sure has a simple solution, but basicaly... I'm making an actionscript game, and I want the player to be able to click on a book and then for a key to appear. I can get both these elements to disappear. I just can't figure out how to have the key invisible until someone clicks the book.

Here is the code:

import flash.events.MouseEvent;

book.addEventListener(MouseEvent.CLICK,getBook);
key.addEventListener(MouseEvent.CLICK,getKey);
//door.addEventListener(MouseEvent.CLICK,gotoBedroom);

var gotBook:Boolean = false;
var gotKey:Boolean = false;


function getKey(evt:MouseEvent):void{
    if(gotBook==false){
        key.visible = false;
    }else{
        key.visible = true;
    }
}

if(gotBook==true){
    book.visible = false;
    key.visible = true;
    }


function getBook(evt:MouseEvent):void{
    book.visible = false;
    key.visible = true;

}

Upvotes: 1

Views: 14802

Answers (1)

shanethehat
shanethehat

Reputation: 15570

Just set its visible property to false at the point that it is added to the stage.

Assuming that your code is on the frame where these objects are added, you can set it to invisible as you create your listeners:

import flash.events.MouseEvent;

book.addEventListener(MouseEvent.CLICK,getBook);
key.addEventListener(MouseEvent.CLICK,getKey);
//door.addEventListener(MouseEvent.CLICK,gotoBedroom);

var gotBook:Boolean = false;
var gotKey:Boolean = false;

key.visible = false;

Upvotes: 1

Related Questions