如何在 Flash 文件上添加重置按钮?

发布于 2024-10-27 08:27:50 字数 46 浏览 1 评论 0原文

如何制作重置按钮,以便在文件结束时将所有变量和代码重置为默认运行时代码和框架?

How can I make a reset button so when the file ends it resets all variables and code to the default run-time code and frame?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

Saygoodbye 2024-11-03 08:27:50

只需在舞台的最后一帧(或您想要的位置)添加一个按钮,例如“resetButton_mc”。

resetButton_mc.addEventListener(MouseEvent.CLICK, reset);

function reset(event:MouseEvent):void
{
     //Reset all variables and send the playhead to the appropriate frame
};

干杯,

Just add a button to the stage on the last frame (or where you want to), let's say "resetButton_mc".

resetButton_mc.addEventListener(MouseEvent.CLICK, reset);

function reset(event:MouseEvent):void
{
     //Reset all variables and send the playhead to the appropriate frame
};

Cheers,
Rob

瞎闹 2024-11-03 08:27:50

创建一个按钮实例,例如resetBtn,

resetBtn.onRelease = function(){
    //manually reset each variable
        userName = "";
        userAge = 0;
        .
        .
        .

        }

但这仍然使用一个函数。

Make a button instance, say resetBtn

resetBtn.onRelease = function(){
    //manually reset each variable
        userName = "";
        userAge = 0;
        .
        .
        .

        }

This still uses a function though.

鹿港小镇 2024-11-03 08:27:50

正如其他人所说,Flash Player 中没有真正的重置方法。根据项目的复杂性,将每个属性和变量设置回默认值可能无法管理。

如果是这种情况,您可能需要考虑两个选项:

将代码包装在具有附加“解构”方法的类中。解构方法应该照顾事件侦听器,而不是其他。构造函数应该调用像 init 这样的方法来设置所有变量。这样你就不会加倍代码。

例如:

package {
    import flash.events.Event;
    import flash.events.EventDispatcher;

    public class Foo extends EventDispatcher {

        private var _a:String;

        public function Foo()  {
            init();
        }   

        public function init():void {
            _a = "Default Value";
            addEventListener(Event.ENTER_FRAME, onEnter);
        }

        public function deconstruct():void {
            // Clean up time
            removeEventListener(Event.ENTER_FRAME, onEnter);
        }

        private function onEnter(e:Event):void {
            trace("frame");
        }

        public function get a():String { return _a; }       
        public function set a(value:String):void { _a = value; }
    }
}

然后在你的主时间线上

var foo:Foo = new Foo();

resetButton.addEventListener(MouseEvent.CLICK, onClick);

function onClick(e:MouseEvent):void {
    foo.deconstruct();
    foo = new Foo();
}

这确保你真正重置

As others have said there is no real reset method within the Flash Player. Depending on the complexity of the project, setting every property and variable back to their defaults may not be manageable.

If this is the case you might want to consider two options:

Wrap your code in a class which has an additional 'deconstruct' method. The deconstruct method should look after eventlisteners and what not. The constructor should call a method like init to setup all the variables. This way your not doubling up code.

For example:

package {
    import flash.events.Event;
    import flash.events.EventDispatcher;

    public class Foo extends EventDispatcher {

        private var _a:String;

        public function Foo()  {
            init();
        }   

        public function init():void {
            _a = "Default Value";
            addEventListener(Event.ENTER_FRAME, onEnter);
        }

        public function deconstruct():void {
            // Clean up time
            removeEventListener(Event.ENTER_FRAME, onEnter);
        }

        private function onEnter(e:Event):void {
            trace("frame");
        }

        public function get a():String { return _a; }       
        public function set a(value:String):void { _a = value; }
    }
}

Then on your main timeline

var foo:Foo = new Foo();

resetButton.addEventListener(MouseEvent.CLICK, onClick);

function onClick(e:MouseEvent):void {
    foo.deconstruct();
    foo = new Foo();
}

This ensures you are truly resetting

倾城°AllureLove 2024-11-03 08:27:50
btn.addEventListener(MouseEvent.CLICK, onClick);
function onClick(e:MouseEvent):void
{
    navigateToURL(new URLRequest(stage.LoaderInfo.url), '_level0');
}

上面的代码将重新加载您的 swf 文件

btn.addEventListener(MouseEvent.CLICK, onClick);
function onClick(e:MouseEvent):void
{
    navigateToURL(new URLRequest(stage.LoaderInfo.url), '_level0');
}

This above code will reload your swf file

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文