如何使动作脚本中的项目不可见
这听起来可能是一个简单的问题,我确信有一个简单的解决方案,但基本上......我正在制作一个动作脚本游戏,我希望玩家能够单击一本书,然后出现一个键。我可以让这两个元素消失。我只是不知道如何在有人点击这本书之前让钥匙不可见。
这是代码:
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;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需在将其添加到舞台时将其
visible
属性设置为 false 即可。假设您的代码位于添加这些对象的框架上,您可以在创建侦听器时将其设置为不可见:
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: