A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: AS3 Flash Classes Inheritance error

  1. #1
    Junior Member
    Join Date
    Feb 2001
    Posts
    5

    Unhappy AS3 Flash Classes Inheritance error

    Hey there, I am trying to pass a value from the Doc class to* subClass1. This part work fine. subClass1 receives the value and sets an internal variable to the value it got from the Doc class. When I set subClass2 to inherite subClass1 variable I get an error* "1203: No default constructor found in base class Aclass."

    I dont know what I am doing wrong.* Can anyone Help!

    Below is the code of the classes

    Doc Class code

    package
    {
    import flash.display.MovieClip;
    import flash.events.MouseEvent;

    public class Main extends MovieClip{
    var maker:Number = 20

    public function Main(){

    btn.addEventListener(MouseEvent.MOUSE_DOWN, checker);
    }
    function checker(event:MouseEvent){
    var a_class:Aclass=new Aclass(maker);
    trace(a_class.types)
    var b_class:Bclass=new Bclass();
    trace(b_class.types)
    }

    }
    }

    subClass1 code

    package{
    public class Aclass {
    public var types:Number
    public function Aclass(_type:Number){
    types = _type
    trace('Aclass has been instantiate');
    }
    }

    SubClass2 code

    package
    {
    public class Bclass extends Aclass
    {
    public function Bclass(){
    }
    }
    }

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    package {
    	import flash.display.MovieClip;
    	import flash.events.MouseEvent;
    	import Aclass;
    	import Bclass;
    
    	public class Main extends MovieClip {
    		var maker:Number=20;
    
    		public function Main() {
    
    			btn.addEventListener(MouseEvent.MOUSE_DOWN,checker);
    		}
    		function checker(event:MouseEvent) {
    			var a_class:Aclass=new Aclass(maker);
    			trace(a_class.types);
    			var b_class:Bclass=new Bclass();
    			trace(b_class.types);
    		}
    	}
    }
    Code:
    package {
    
    	public class Aclass {
    		
    		public var types:Number;
    
    		public function Aclass(_type:Number) {
    			types=_type;
    			trace('Aclass has been instantiate');
    		}
    	}
    }
    Code:
    package {
    	import Aclass;
    
    	public class Bclass extends Aclass {
    
    		public function Bclass() {
    			super(types);
    			trace('Bclass has been instantiate');
    		}
    	}
    }

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    That should compile, but be aware that in the code dawsonk just posted, the new Bclass instance's types property will be null or undefined.

  4. #4
    Junior Member
    Join Date
    Feb 2001
    Posts
    5
    It worked but in Bclass in the public function, is there any way that I can just get the value of the variable "types" that is in the Aclass without having to pass a value from the Bclass and not have an error?

    public function Bclass() {
    super(types);
    trace('Bclass has been instantiate');
    }

  5. #5
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Aclass doesn't have a types value. The instance of Aclass created in Main does, but the class itself does not, which is why Bclass cannot access it. Do you understand the difference between classes and instances (seriously asking, not trying to be mean)?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center