-1

我正在研究我的 AS3,但我被卡住了。此代码在我的 AS2 文件中。您如何将此代码转换为 AS3?当我设置为 AS3 并发布时,出现此错误消息:

场景 1,图层“图层 1”,第 1 帧,第 6 行
1046:找不到类型或不是编译时常量:颜色。

请帮忙.... :(

i=0;
function cogalt() {
i++;
mc.duplicateMovieClip("mc"+i, i);
//
var my_color:Color = new Color(_root["mc"+i]);
_root["mc"+i].renk1=random(255);
_root["mc"+i].renk2=random(255);
_root["mc"+i].renk3=random(255);
my_color.setRGB(_root["mc"+i].renk1<<16 | _root["mc"+i].renk2<<8 | _root["mc"+i].renk3 );
//
_root["mc"+i]._x = tiklax;
_root["mc"+i]._y = tiklay;
//
_root["mc"+i].deger2 = random(2);
//
_root["mc"+i].ziplama = 1+random(10);
_root["mc"+i]._width = _root["mc"+i]._height = 1+random(10);
//
if (_root["mc"+i].deger2 == 0) {
    _root["mc"+i].degerx = -(1+random(4));
} else {
    _root["mc"+i].degerx = +(1+random(4));
}
_root["mc"+i].onEnterFrame = function() {
    this.ziplama -=1;
    this._y-= this.ziplama;
    this._x += this.degerx;
    this._alpha -= 4;
    if (this._alpha<0) {
        delete this.onEnterFrame;
        removeMovieClip(this);
    }
};
      }
      mc.startDrag(true);
4

1 回答 1

0

1. 这是一个关于动态设置 MovieClip 颜色的链接,AS2 到 AS3: http ://evolve.reintroducing.com/2008/02/26/as2-to-as3/as2-%E2%86%92-as3-setting -a-movieclips-color/

2. 你还会碰到另一个问题。as3 中没有重复的MovieClip()。

您必须创建一个 MovieClip 的子类并将其链接到您要复制的图形。在创建子类时不要忘记选择“Export for Actionscript”。

那么你会有

var mc:MovieClip = new SubclassOfMovieClip()
addChild(mc)

然后您可能必须将每个实例保存到 Array/Vector 中,以便保留对对象的引用。

3. as3中添加监听器从这里开始

mc.onEnterFrame=function(){}

对此

mc.addEventListener(Event.ENTER_FRAME,onEnterFrame)

function onEnterFrame(evt:Event){}
于 2013-08-19T10:59:05.480 回答