如何将AS2调整为AS3?

时间:2010-08-16 18:08:53

标签: flash actionscript-3 actionscript actionscript-2

AS2代码是:

MovieClip.prototype.setModel = function(m)
{
    this.model = m;
    this.drawModel(m);
}

MovieClip.prototype.drawModel = drawModel;

我试过了:

package
{
    import flash.display.MovieClip;

    public class Prototype extends MovieClip
    {
        public function Prototype()
        {
            super();
        }

        public function setModel(m)
        {
            this.model = m;
            this.drawModel(m);
        }

        public function setDrawModel(m)
        {
            this.drawModel = m;
        }

    }
}

但MovieClip中没有“this.model”“drawModel(m)”。

有什么想法吗?

2 个答案:

答案 0 :(得分:0)

您已定义模型和drawModel。我只看到setModel和setDrawModel而没有变量。

因此,如果您在课程中添加以下内容:

private var model:type;

然后你的this.model会起作用。

答案 1 :(得分:0)

 public class Whatever extends MovieClip
 {
    private var _model:DisplayObject;

    public function set model(m:Object):void
    {
       this._model = m;
       this.drawModel();
    }

    private function drawModel():void
    { 
        _model.graphics.beginFill(0); //etc...
    }
 }

然后在另一堂课中,你可以这样做

 var whatever:Whatever = new Whatever();
 whatever.model = new DisplayObject();