简体   繁体   English

文档类中所有框架的AS3设置按钮

[英]AS3 Setup Buttons for All Frames in Document Class

I'm making a simple interface with Flash. 我正在使用Flash创建一个简单的界面。 Let's say we've got: 假设我们有:

frame 1: 1 button that advances to frame 10 ( goto10 ) 框架1:1按钮前进到框架10( goto10

frame 10: 2 buttons, one advances to frame 20 ( goto20 ), one opens a URL ( openURL ) 第10帧:2个按钮,一个前进到第20帧( goto20 ),一个打开URL( openURL

frame 20: 3 buttons, one goes back to frame 1 ( goto1 ), one goes to frame 10 ( goto10 ), and one opens a URL ( openURL ) 第20帧:3个按钮,一个回到第1帧( goto1 ),一个回到第10帧( goto10 ),一个打开URL( openURL

package {

import flash.display.MovieClip
import flash.events.Event;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.display.SimpleButton;

public class NKE_DocumentClass extends MovieClip {
    public var goto1:SimpleButton = new SimpleButton();
    public var goto10:SimpleButton = new SimpleButton();
    public var goto20:SimpleButton = new SimpleButton();
    public var openURL:SimpleButton = new SimpleButton();

    public function NKE_DocumentClass() {   
        goto1.addEventListener(MouseEvent.CLICK,function(self:MouseEvent):void{clickGo(self,1)});
        goto10.addEventListener(MouseEvent.CLICK,function(self:MouseEvent):void{clickGo(self,10)});
        goto20.addEventListener(MouseEvent.CLICK,function(self:MouseEvent):void{clickGo(self,20)});
        openURL.addEventListener(MouseEvent.CLICK,function(self:MouseEvent):void{urlGo(self,"http://google.com")});
        }

    public function clickGo(event:MouseEvent, nextCue:int):void {
        gotoAndStop(nextCue);
        trace("Advanced to: " + nextCue);
        }

    public function urlGo(event:MouseEvent, goURL:String):void {
        var request:URLRequest = new URLRequest(goURL);
        new URLLoader(request);
        trace("Executed URL: " + goURL);
        }

}

}

Problem is, once I leave frame 1, none of the buttons work... they're simply unresponsive. 问题是,当我离开第1帧时,所有按钮都不起作用...它们只是无响应。 It seems like the code doesn't stay loaded once it leaves frame 1. 好像代码离开第1帧后就不会保持加载状态。

Thoughts? 有什么想法吗?

I'm pressuming the problem is because when this code is first executed (as a Document Class) the only button that exists is the button on frame 1? 我要强调的问题是,当第一次执行此代码(作为文档类)时,唯一存在的按钮是第1帧上的按钮吗? This is under the assumption than you've created buttons in the Flash IDE then added them to the stage from the library on the specific keyframes. 假设您没有在Flash IDE中创建按钮,然后将它们从库中的特定关键帧添加到场景中。

I see you've created the SimpleButtons programmatically but since they haven't been added to the stage in the code you've shown, the presumption is that you've just called them the same names as the buttons you've placed on stage? 我看到您已经以编程方式创建了SimpleButtons,但是由于尚未将它们添加到所显示的代码中的舞台上,因此推测是您已经将它们命名为与放置在舞台上的按钮相同的名称? Correct me if I'm wrong and I'll try to offer some other advice if the below doesn't help. 如果我错了,请纠正我,如果以下内容没有帮助,我会尝试提供其他建议。

One solution would be to create them all on the first frame then switch their visibility on and off depending on when you need them. 一种解决方案是在第一帧上全部创建它们,然后根据需要的时间打开和关闭它们的可见性。

If you're not sure how: 如果不确定如何:

goto10.visible = false;

etc etc

I can't remember now without testing but if you have placed them all on the stage on different keyframes this may cause a problem. 我现在不记得没有测试,但是如果您将它们全部放置在舞台上的不同关键帧上,可能会引起问题。

Back in the days of putting code on the timeline if you put code on frame 1 but it referenced objects that weren't on frame 1 then the code would fail (this is probably what's happening with your document class - it's running when not all objects exist). 早在将代码放置在时间轴上的日子里,如果您将代码放置在第1帧上,但它引用了不在第1帧上的对象,则代码将失败(这可能是您的文档类所发生的事情-当并非所有对象都在运行时,它正在运行存在)。

I would make sure they're all on one layer without any keyframes, from frame 1, and you just switch their visibility on and off. 我要确保它们全部位于一层,没有任何关键帧(从第1帧开始),并且您只需打开和关闭它们的可见性即可。 Alternatively, let your classes add and remove the buttons and other interface elements and don't use the timeline at all. 或者,让您的类添加和删除按钮和其他界面元素,并且根本不使用时间轴。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM