如何避免此错误“继承定义存在冲突”?

时间:2009-10-18 02:39:43

标签: flash actionscript-3

我在库中有3 mc: category1 category2 category3 ,在每个库中我都有相同实例名称的mc: _background _picture ,但完全不同的竞争。我想要做的是创建一个 SuperCategory 类,它将在_background,_picture上执行相同的操作。因此,在库中我执行了Export for Actionscript Category1 Category2 Category3

public class SuperCategory extends MovieClip
{
    public var _picture:MovieClip;
    public var _background:MovieClip;
    public var time:int = 0;

    public function SuperCategory() 
    {
         addEventListener(MouseEvent.ROLL_OVER, onRollOver)
    }
    public function onRollOver(event:MouseEvent):void
    {
         TweenMax.to(_picture,time,{alpha:0.2});
    }

}

我希望扩展这个类

public class Category1 extends SuperCategory
{
    public function Category1()
    {
        time = 2;
        super();
    }
}

我知道冲突发生在公共var _picture和库中具有名为_picture的实例的mc之间,但我怎么能做这样的事情并避免这个错误呢?

1 个答案:

答案 0 :(得分:1)

如果在类别MC中您将实例名称更改为其他内容可能是“_pic”。 然后在构造函数的Category类中执行以下操作:

public class Category1 extends SuperCategory{    
       public function Category1()    
       {        
          time = 2;        
          super();   
          registerRollOver(_pic);
       }
}

SuperCategory类

 public class SuperCategory extends MovieClip
    {
        public var _picture:MovieClip;
        public var _background:MovieClip;
        public var time:int = 0;

        public function SuperCategory() 
        {

        }
        public function onRollOver(event:MouseEvent):void
        {
           TweenMax.to(_picture,time,{alpha:0.2});
        }

        public function registerRollover(clip:MovieClip):void
        {
           _picture = clip; //in case you want it to be class member still
           _picture.addEventListener(MouseEvent.ROLL_OVER, onRollOver)
        }

    }