在 AS3 中隐藏按钮? [英] Hide a Button in AS3?
问题描述
我有一个名为 myBtn 的按钮.
I have a button called myBtn.
在我在第 1 帧的操作中,我都尝试了:
In my actions in Frame 1, I have tried both:
myBtn.visibility = false;
myBtn.enabled = false;
两者都给我同样的错误:
Both give me the same error:
1120:访问未定义的属性 myBtn.
1120: Access of undefined property myBtn.
推荐答案
ok.有几种方法可以做到这一点.第一个只是涉及使用时间线.
ok. There are a couple of ways that you can do this. The first just involves using the timeline.
方法 1 - 时间线
步骤 1. 转到窗口选项卡,然后选择组件.将 Button 实例拖到舞台上.
Step 1. Go to Window tab, then select components. Drag a Button instance onto the stage.
第 2 步.在属性面板中,在显示实例名称"的地方,替换为myBtn"(确保不要使用引号:P)
Step 2. In the properties panel, where it says 'Instance Name', replace with "myBtn" (make sure you don't use the quotes :P)
第 3 步.在时间轴的第 1 帧中输入此代码.
Step 3. On the timeline enter this code in frame 1.
myBtn.visible = false;
方法 2 - 文档类
第 1 步:在舞台上放置一个实例,如时间轴中一样
Step 1. Place an instance on the stage as in the timeline
第 2 步.创建一个类,我们称之为资源.
Step 2. Create a class, lets call it Resource.
步骤 3. 添加
import flash.display.SimpleButton;
步骤 4. 创建一个公共静态成员
Step 4. Create a public static member
public static var BTN_MY_BUTTON:SimpleButton;
步骤 5. 在您的文档类中将其添加到构造函数中.
Step 5. In your document class add this to the contstructor.
addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true);
步骤 6. 添加此功能
Step 6. Add this function
private function init(e:Event):void
Resource.BTN_MY_BUTTON = myBtn;
}
第 7 步.现在,您可以在任何课程中访问该按钮
Step 7. Now in any class you can access the button by going
Resource.BTN_MY_BUTTON.visible = false;
这篇关于在 AS3 中隐藏按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!