A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 36

Thread: no default constructor found in base class ball

  1. #1
    Senior Member
    Join Date
    Jul 2008
    Posts
    418

    no default constructor found in base class ball

    i want the class BeginBall to extend Ball, but when i do so, this error shows up.
    this is my code:
    PHP Code:
    package
    {
        
    import flash.events.Event;
        
    import flash.display.MovieClip;
        
        public class 
    Ball extends MovieClip
        
    {
            public var 
    nSpeedX:Number;
            public var 
    nSpeedY:Number;
            public var 
    ballNr:int;
            const 
    BALLDIAMETER 10;
            private var 
    nStageWidth:Number 500;
            private var 
    nStageHeight:Number 400;
            
            public function 
    Ball X,Y,NSpeedX:NumberNSpeedY:Number ) : void
            
    {
                
    nSpeedX NSpeedX;
                
    nSpeedY NSpeedY;
                
    X;
                
    Y;
                
                
    this.addEventListener Event.ENTER_FRAMEonEnterFrameHandler );
            }
            
            private function 
    onEnterFrameHandler E:Event ) : void
            
    {
                
    this.-= nSpeedX;
                
    this.-= nSpeedY;
                
                if ( 
    this.>= nStageWidth BALLDIAMETER 16 )
                {
                    
    this.nStageWidth BALLDIAMETER 16;
                    
    nSpeedX *= -1;
                }
                else if ( 
    this.<= BALLDIAMETER 16 )
                {
                    
    this.BALLDIAMETER 16;
                    
    nSpeedX *= -1;
                }
                
                if ( 
    this.>= nStageHeight BALLDIAMETER 16 )
                {
                    
    this.nStageHeight BALLDIAMETER 16;
                    
    nSpeedY *= -1;
                }
                else if ( 
    this.<= BALLDIAMETER 16 )
                {
                    
    this.BALLDIAMETER 16;
                    
    nSpeedY *= -1;
                }
                
            }
        }
    //end of class
        
        
    public class BeginBall extends Ball
        
    {
            
    //alles over spatieknop en muisknop etc.
        
    }

    i tried to do public last class Ball, butit says access identifiers are not allowed with namespace attributes.
    how can i let BeginBall normally inherit Ball's constructor, or if its not possible, make a new one for BeginBall?

  2. #2
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    Try moving the helper class BeginBall outside of the package brackets.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  3. #3
    Senior Member
    Join Date
    Jul 2008
    Posts
    418
    doesn't work. same error.

  4. #4
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    How are you trying to instantiate it?
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  5. #5
    Senior Member
    Join Date
    Jul 2008
    Posts
    418
    PHP Code:
    var shootBall:ShootBall = new ShootBall;
                
    addChild(shootBall); 
    changed the name in ShootBall btw, it's more suitable.

  6. #6
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    also try:

    Constants

    ActionScript 3.0 supports the const statement, which you can use to create constants. Constants are properties with a fixed value that cannot be altered. You can assign a value to a constant only once, and the assignment must occur in close proximity to the declaration of the constant. For example, if a constant is declared as a member of a class, you can assign a value to that constant only as part of the declaration or inside the class constructor.

    The following code declares two constants. The first constant, MINIMUM, has a value assigned as part of the declaration statement. The second constant, MAXIMUM, has a value assigned in the constructor.

    class A
    {
    public const MINIMUM:int = 0;
    public const MAXIMUM:int;

    public function A()
    {
    MAXIMUM = 10;
    }
    }
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  7. #7
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    Well you define parameters for the constructor, but you are not passing any. a "default" constructor is one that takes no parameters, so what it is telling you is that it can not find the constructor defined in the way you are trying to use it.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  8. #8
    Senior Member
    Join Date
    Jul 2008
    Posts
    418
    ooh stupid me.
    ps. i use constants. but u probably mean the 16 ? yeah i should change that into a constant.

    edit: i now assigned the right variables in the instanciation, but the same problem exists, only this time it gives the same error twice. :/
    Last edited by omniscient232; 08-19-2008 at 10:12 AM.

  9. #9
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    I was actually referring to the fact that you did not explicitly declare an access modifier before it. Which I guess works and would default to internal I believe.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  10. #10
    Senior Member
    Join Date
    Jul 2008
    Posts
    418
    huh?? so what do i have to do?

  11. #11
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,358
    Glancing at the code it looks like you have two classes in the same package. You should break them out into separate class files.

    When you extend Ball, the constructor of the subclass must call super with the necessary arguments ( X,Y,NSpeedX:Number, NSpeedY:Number ) so that the Ball constructor for the subclass instance can be called correctly. Similarly, make sure you create your subclass instance with the right number of arguments... which is what I assume you fixed in your last post?
    Last edited by senocular; 08-19-2008 at 10:44 AM.

  12. #12
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    The problem is with your sub class. Since it extends Ball, it would have to construct ball when it is created and since it does not provide any parameters for the ball constructor, you get your error message.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  13. #13
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    LOL he beat me to it. Thanks Senocular.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  14. #14
    Senior Member
    Join Date
    Jul 2008
    Posts
    418
    i put it in a different as file in the same package, but it doesnt work. do i have to put it in another package? that would kinda annoy me. can't i do it someway different?

  15. #15
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,358
    They don't have to be in different pacakges. Packages are just for organization.

    You just need to make sure you call super() where needed and with the right arguments.

    You may need to repost what code you're using now.

  16. #16
    Senior Member
    Join Date
    Jul 2008
    Posts
    418
    only the shootball instantiation changed:
    var shootBall:ShootBall = new ShootBall(SHOOTBALLDOWN_X,SHOOTBALL_Y,0,0);
    what is super()?

  17. #17
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,358
    You haven't posted the ShootBall class.

    super() is what lets you access superclass members, including the constructor. When you create a subclass of another class that is defined with required parameters in the constructor, your subclass is responsible for making sure those parameters are taken care of by passing arguments into those parameters of the superclass constructor. You call the superclass constructor through super.

    So in your ShootBall constructor, you must call super using whatever values you see fit to define for ( X,Y,NSpeedX:Number, NSpeedY:Number )

    Code:
    public function ShootBall(){
        super(0,0, 10, 5);
    }

  18. #18
    Senior Member
    Join Date
    Jul 2008
    Posts
    418
    this is what i have now, but it still doesnt work.(ignore everything under the constructor)

    PHP Code:
    package
    {
        public class 
    ShootBall extends Ball
        
    {
            private var 
    touchable:Boolean false;
            private var 
    speedingLvl;
            
    alles over spatieknop en muisknop etc.
            public function 
    ShootBallX,Y,NSpeedX:NumberNSpeedY:Number)
            {
                
    super(X,Y,NSpeedX:NumberNSpeedY:Number)
            }
            
            function 
    muisKnopKlik(event:Event)
            {
                
    //balkje begint te gaan
                
    speedingLvl 0;
            }
            function 
    muisKnopLos(event:Event)
            {
                
    mouseX x
                mouseY 
    y
                
                
                
                
    function shootShootBall(hspeed,vspeed)
                {
                    
    nSpeedX hspeed;
                    
    nSpeedY vspeed;
                    
    touchable true;
                }
            }
            
        }


  19. #19
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,358
    asside from the misplaced "alles over spatieknop en muisknop etc." it seems passable.

    Now, if you create an instance of ShootBall, you will need to be sure to pass in X,Y,NSpeedX:Number, NSpeedY:Number to that (not present in your previous code).

  20. #20
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    import ball class.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


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