影片剪辑中的 AS3 按钮
我对闪光完全是个菜鸟,我知道我只是在这里遗漏了一些明显的东西。
我已将屏幕设计为影片剪辑,并在每个影片剪辑中都有将菜单屏幕链接在一起的按钮。使用时间线和代码片段,一切都运行良好。
现在,我尝试在代码中执行此操作,但遇到了一些问题:
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
public class Main extends MovieClip {
public function Main() {
// define variable main as the movieclip main
var main = new Main_menu();
var instructions = new instructions();
//add the movieclip to the stage
addChild(main);
// Tell the button to run function on_play.....
Instructions_btn.addEventListener(MouseEvent.CLICK, on_play_button_clicked);
}
// what the button does
public function on_play_button_clicked(event:MouseEvent) {
addChild(instructions);
}
}
}
我可以显示影片剪辑 Main,并且由于我在 Flash 内的影片剪辑中添加了按钮,它们显示良好,并且光标更改为手指单击图标:-)
我似乎无法解决的是如何获取类名称为:instructions_btn 的按钮来添加屏幕:单击它时的说明。
可能很简单,但我正在拔头发!
I'm a complete noob to flash and know I'm just missing something obvious here.
I have designed my screens as a movieclip and have buttons in each of the movieclips which link the menu screens together .. everything worked fine using the timeline and code snippets.
Now, I'm trying to do it in code, I'm having some problems:
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
public class Main extends MovieClip {
public function Main() {
// define variable main as the movieclip main
var main = new Main_menu();
var instructions = new instructions();
//add the movieclip to the stage
addChild(main);
// Tell the button to run function on_play.....
Instructions_btn.addEventListener(MouseEvent.CLICK, on_play_button_clicked);
}
// what the button does
public function on_play_button_clicked(event:MouseEvent) {
addChild(instructions);
}
}
}
I can get the movie clip Main to display and since ive added the buttons in the movieclip within flash they display fine and the cursor changes to a finger click icon :-)
What i cant seem to work out is how to get the button with class name: instructions_btn to add the screen : instructions when I click it.
Dead easy probably but I'm pulling my hair out!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您对变量实例“指令”和类“指令”使用相同的名称。显然,这是行不通的。坚持命名约定:类名的首字母应为大写,实例名称的首字母应为小写:
此外,您在 Main 的构造函数中将指令声明为局部变量,但尝试将其添加到阶段中事件处理程序 - 当它不再可用时。如果您希望变量存在于方法的作用域之外,请将其声明为成员:
You are using the same name for you variable instance "instructions" and for the class "instructions". This, obviously, cannot work. Stick to naming conventions: The first letter of a Class name should be upper case, that of an instance name lower case:
Also, you are declaring instructions as a local variable inside the constructor for Main, but try to add it to the stage in the event handler - when it is no longer available. If you want your variable to exist outside of a method's scope, declare it as a member: