Unless you're using packages, that won't be necessary.Quote:
Originally Posted by kortex
Printable View
Unless you're using packages, that won't be necessary.Quote:
Originally Posted by kortex
Yeah, but I have run into a couple of occasions where I had to do it anyway, so I thought I might suggest it.
the alles over.... should have been a comment.
but i did pass that all, and it still didnt work:
and are you sure this is ok? it like kind of weird.PHP Code:var shootBall:ShootBall = new ShootBall(SHOOTBALLDOWN_X,SHOOTBALL_Y,0,0);
PHP Code:public function ShootBall( X,Y,NSpeedX:Number, NSpeedY:Number)
{
super(X,Y,NSpeedX:Number, NSpeedY:Number)
}
super() is called just like any other function. You don't include the typing information. See my example above
but i want to put that information in the class instantiation
and it still doesnt work
What senocular is saying is that you do not need to put the typing information when you are calling the function (passing in values). That is done in the defining class.
i didnt...
@senocular Been playing with the classes without the import and low and behold, sure enough if they are in the same folder; no import statement needed. Was not aware of that, thanks.
it is in the code you posted:
Quote:
public function ShootBall( X,Y,NSpeedX:Number, NSpeedY:Number)
{
super(X,Y,NSpeedX:Number, NSpeedY:Number)
}
i changed it, still doesnt work.
please give us an update of the code you're using; all of itQuote:
Originally Posted by omniscient232
you can ignore most of it ofcourse:
class BallController:class Ball:PHP Code:package
{
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
import flash.events.KeyboardEvent;
public class BallController extends MovieClip
{
const BALLDIAMETER = 10;
const SHOOTBALLUP_Y = BALLDIAMETER*0.5+16;
const SHOOTBALLDOWN_Y = 600-(BALLDIAMETER*0.5+16);
const SHOOTBALL_X = 200;
private var mcBallContainer:MovieClip;
private var nStageWidth:Number = 500;
private var nStageHeight:Number = 400;
public var numBalls:int;
private var shootBallDown:Boolean = true;
var shootBall:ShootBall;
public function BallController()
{
mcBallContainer = new MovieClip() ;
mcBallContainer.x = mcBallContainer.y = 0;
stage.addChild(mcBallContainer);
this.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
shootBall = new ShootBall(SHOOTBALL_X,SHOOTBALLDOWN_Y,0,0);
addChild(shootBall);
for ( var i = 0; i < 2; i++ )
{
createBall(Math.random() * nStageWidth,Math.random() * nStageHeight,Math.floor ( ( Math.random() * 12 ) - 4 ), Math.floor ( ( Math.random() * 12 ) - 4 ));
}
}
private function enterFrameHandler(E:Event): void
{
for(var i = 0; i < mcBallContainer.numChildren; i++)
{
var mcBall1:* = mcBallContainer.getChildAt(i);
for (var j = i + 1; j < mcBallContainer.numChildren; j++)
{
var mcBall2:* = mcBallContainer.getChildAt(j);
var nDistX:Number = Math.abs ( mcBall1.x - mcBall2.x );
var nDistY:Number = Math.abs ( mcBall1.y - mcBall2.y );
var nDistance:Number = Math.sqrt(nDistX * nDistX + nDistY * nDistY);
if (nDistance < BALLDIAMETER*2)
{
solveBalls (mcBall1, mcBall2);
}
}
}
}
public function createBall(X,Y,speedX,speedY)
{
var mcBall:Ball = new Ball(X,Y,speedX,speedY);
mcBall.ballNr = numBalls;
mcBallContainer.addChild(mcBall);
numBalls ++;
}
private function solveBalls (MCBallA:MovieClip, MCBallB:MovieClip):void
{
var nX1:Number = MCBallA.x;
var nY1:Number = MCBallA.y;
var nDistX:Number = MCBallB.x - nX1;
var nDistY:Number = MCBallB.y - nY1;
var nDistance:Number = Math.sqrt ( nDistX * nDistX + nDistY * nDistY );
var nRadiusA:Number = MCBallA.width/2;
var nRadiusB:Number = MCBallB.width/2;
//var nRadius:Number = 10;
var nNormalX:Number = nDistX/nDistance;
var nNormalY:Number = nDistY/nDistance;
var nMidpointX:Number = ( nX1 + MCBallB.x )/2;
var nMidpointY:Number = ( nY1 + MCBallB.y )/2;
MCBallA.x = nMidpointX - nNormalX * nRadiusA;
MCBallA.y = nMidpointY - nNormalY * nRadiusA;
MCBallB.x = nMidpointX + nNormalX * nRadiusB;
MCBallB.y = nMidpointY + nNormalY * nRadiusB;
var nVector:Number = ( ( MCBallA.nSpeedX - MCBallB.nSpeedX ) * nNormalX )+ ( ( MCBallA.nSpeedY - MCBallB.nSpeedY ) * nNormalY );
var nVelX:Number = nVector * nNormalX;
var nVelY:Number = nVector * nNormalY;
MCBallA.nSpeedX -= nVelX;
MCBallA.nSpeedY -= nVelY;
MCBallB.nSpeedX += nVelX;
MCBallB.nSpeedY += nVelY;
}
private function shootBallChange()
{
if (shootBall.touchable == false)
{
if (shootBallDown = true){
shootBallDown = false;
shootBall.y = SHOOTBALLDOWN_Y;
}
else
{
shootBallDown = true;
shootBall.y = SHOOTBALLUP_Y;
}
}
}
}//end of class
}//end of package
class ShootBall: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 = 400;
private var nStageHeight:Number = 600;
public function Ball ( X,Y,NSpeedX:Number, NSpeedY:Number ) : void
{
nSpeedX = NSpeedX;
nSpeedY = NSpeedY;
x = X;
y = Y;
this.addEventListener ( Event.ENTER_FRAME, onEnterFrameHandler );
}
private function onEnterFrameHandler ( E:Event ) : void
{
this.x -= nSpeedX;
this.y -= nSpeedY;
if ( this.x >= nStageWidth - BALLDIAMETER - 16 )
{
this.x = nStageWidth - BALLDIAMETER - 16;
nSpeedX *= -1;
}
else if ( this.x <= BALLDIAMETER + 16 )
{
this.x = BALLDIAMETER + 16;
nSpeedX *= -1;
}
if ( this.y >= nStageHeight - BALLDIAMETER - 16 )
{
this.y = nStageHeight - BALLDIAMETER - 16;
nSpeedY *= -1;
}
else if ( this.y <= BALLDIAMETER + 16 )
{
this.y = BALLDIAMETER + 16;
nSpeedY *= -1;
}
}
}//end of class
/*public class PlayerBall extends Ball
{
}*/
}
PHP Code:package
{
import flash.events.Event
public class ShootBall extends Ball
{
public var touchable:Boolean = false;
private var speedingLvl;
private var barSpeed;
//alles over spatieknop en muisknop etc.
public function ShootBall( X,Y,NSpeedX:Number, NSpeedY:Number)
{
super(X,Y,NSpeedX, NSpeedY)
}
function muisKnopKlik(theEvent:Event):void
{
//balkje begint te gaan
speedingLvl = 0;
}
function muisKnopLos(theEvent:Event):void
{
var dx:Number = parent.mouseX - x;
var dy:Number = parent.mouseY - y;
var angle:Number = Math.atan2(dy, dx);
nSpeedX += Math.cos(angle)*barSpeed;
nSpeedY += Math.sin(angle)*barSpeed;
touchable = true;
}
}
}
Are you getting errors?
ops. forgot to save :/ yeah this one works, after i removed the type definitions in the super() function.
thanks alot guys.
;)
:thumbsup: