【问题标题】:How do I convert this function into ActionScript 3.0?如何将此函数转换为 ActionScript 3.0?
【发布时间】:2012-11-12 05:52:32
【问题描述】:

你能帮我把这个函数转换成 ActionScript 3.0 吗?

for (i=1; i<3; i++) {
    _root["pemain"+i].onEnterFrame = function() {
        ulartangga();
        if (this.temp_nomor<this.nomor) {
            this.temp_nomor++;
        }
        this._x = _root["kotak"+this.temp_nomor]._x;
        this._y = _root["kotak"+this.temp_nomor]._y;
    };
}

我遵循了http://warungflash.com/2009/05/ular-tangga-player-vs-player/的教程

我已经尝试转换成这个:

function onEnterFrame() {
//ulartangga();
if (this.temp_nomor<this.nomor) {
    this.temp_nomor++;
}
this.x = stage["kotak"+this.temp_nomor].x;
this.y = stage["kotak"+this.temp_nomor].y;
}

【问题讨论】:

  • 你试过什么?你得到哪个错误? whathaveyoutried.com
  • 我是初学者,不明白怎么把'_root["pemain"+i].onEnterFrame = function()'转成as3..thx
  • 那么你有什么尝试?理解很重要,否则任何答案都将一文不值。
  • 我试图转换成这个:function onEnterFrame() { //ulartangga(); if (this.temp_nomor
  • 好! :) 然后您应该使用帖子的“编辑”链接,添加一行 EDIT : 然后将您的代码粘贴到那里!这就是这里做事的方式;)如果人们看到你的尝试,他们会更倾向于帮助你,甚至更快!您应该始终这样做,这会使您的问题更有价值且更容易回答。如果你这样做,我会支持你的问题。

标签: actionscript-3 flash


【解决方案1】:

enter-frame 应该是一个 EventListener。假设您的其他代码是正确的,这应该可以工作。

import flash.events.Event;

this.addEventListener(Event.ENTER_FRAME, enterFrameHandler);

function enterFrameHandler(e:Event):void{
    if (this.temp_nomor<this.nomor) {
        this.temp_nomor++;
    }
    this.x = stage["kotak"+this.temp_nomor].x;
    this.y = stage["kotak"+this.temp_nomor].y;
}

【讨论】:

  • 感谢您的帮助,但我仍然遇到问题'在 flash.display.Stage 上找不到属性 kotak3,并且没有默认值。'..
猜你喜欢
  • 2011-01-23
  • 2011-07-11
  • 2020-06-07
  • 2013-04-03
  • 2016-01-01
  • 2020-09-03
  • 2020-07-22
  • 2021-12-12
  • 1970-01-01
相关资源
最近更新 更多