Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I haven't touched Flash in a while and I've forgotten a lot.

I'm trying to get a space-ship symbol to show in the middle of the screen. For some odd reason it isn't showing in the middle of the screen or even appearing. There's no error in the output or an error in the debug.

Here's some code below.

I'm coding in Coda 2 and using Flash to manage the library. I currently only have one class called Game.As and the ship symbol is a MovieClip with the name shipSymbol and the class is defined as shipBase with the base class being flash.display.MovieClip;

package {

import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.display.Stage;
import flash.events.Event;

public class Game extends MovieClip {

    //Spaceship Symbol 
    private static var ship = spaceShip;

    private function initShip(startX = number , startY = number):void {
        ship = new spaceShip();
        this.x = startX;
        this.y = startY;
        startX = stage.stageWidth /2;
        startY = stage.stageHeight /2;
        stage.addChild(spaceShip);
        trace("Space-Ship Spawned");
    }
    public function runGame():void {
        stage.addEventListener(Event.ENTER_FRAME , update);
    }
    override public function update(e:Event):void {
        initShip();
    }
}

}

Thanks, for the help :P

share|improve this question
    
Your code is a little confusing. You seem to be calling initShip() on each frame. The parameters to initShip have default value "number", which is probably undefined. I think you meant to type them as Number, which you would write startX:Number, startY:Number. –  Danik May 25 '12 at 19:48
    
Thanks for the tip! I actually just figured out what was wrong. –  Monstr92 May 25 '12 at 20:59
add comment

1 Answer

up vote 2 down vote accepted

Few things wrong...

parameters should be...

initShip(startX : Number , startY : Number) 

and not

initShip(startX = number , startY = number)

This seems misplace:

startX = stage.stageWidth /2;
startY = stage.stageHeight /2;

This should change from:

stage.addChild(spaceShip);

to

stage.addChild(ship);

Change this

this.x = startX;
this.y = startY;

to

ship.x = startX;
ship.y = startY;

probably not legal:

private static var ship = spaceShip;

set it to null.

If ship still does not appear, then make sure you check the "export symbol" via the library where you typed in "spaceShip" for this symbol (I don't have flash to tell you correct/specific name).

You should have got errors anyway and since you didn't you probably not got the class name field setup in the project dialogue. I can't be more specific on this, someone who has flash on their machine will probably give you a better answer on this.

share|improve this answer
    
Thanks! This worked! –  Monstr92 May 25 '12 at 21:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.