0
votes

First off let me say I'm completely new to flash development, but not OOP. My assignment is to create a real time (meaning using a game loop) Flash game in an object orientated manner. I've been following guides online, and I think I've got the basics down, but my player sprite isn't appearing.

I imported an image into Flash and then converted it into a symbol called Player, and now it's a movie clip. I exported it for ActionScript, and called the class com.Player.

Also, I have set the class of my document to com.Engine (this is where I plan to have my game loop and call methods to other classes).

Then, I created a directory called com in the same directory as my .fla. Inside that directory, I made Engine.as and Player.as, and here's the code for them both:

package com {
    import flash.display.MovieClip;
    import flash.display.Stage;

    public class Engine extends MovieClip {
        public function Engine() {
            // Create a player instance
            var player:Player = new Player();
            stage.addChild(player);
            player.x = stage.stageWidth / 2;
            player.y = stage.stageHeight / 2;

        }
    }
}

--

package com {
    import flash.display.MovieClip;

    public class Player extends MovieClip {
        public function Player() {

        }
    }
}

According to what I know, that should make the player appear in the center of the screen when I run it, but it doesn't. I've verified that the Engine class and constructor is being called using trace("hello world"), and I get that output. I also know that the constructor for the Player class is being called by using the same method. I just don't get why the player doesn't appear on screen.

If I drag the Player symbol (correct terminology?) from my library onto the stage, the player sprite shows up... so I know there's an image attached.

Anyone know what could be going wrong? Thank you in advance :)

1
If you right click on the Player symbol from the library, and go to "Properties...", is "Export for ActionScript" checked, and in the "Class" field, do you see "com.Player"?rid
Yes and yes :) although it has no base class, does that matter?James Dawson
The base class should be flash.display.MovieClip.rid
I'm not sure if you can add it to the stage from within its own class? Try adding to the stage from your main program that actually owns the stage. (I am not at all sure if that is the problem or not but it is worth a shot)M. Laing
It won't let me change it to flash.display.MovieClip, when I enter that and select OK and then re-open the properties window the field is blank again. If I validate the base class definition it says The base class specified is a native class and will be defined in the player at runtime. It cannot be edited.James Dawson

1 Answers

0
votes

is there something in you player sprite? if you made a sprite in an .fla file or something you should extend from that name so:

public class Player extends PlayerSpriteNameThatIsInYourFla

or you should try to draw some graphics in you player class to check if your class is actually showing:

public class Player extends MovieClip()
{
    this.graphics.beginFill(0x00FF00);
    this.graphics.drawRect(0,0,100,100);
    this.graphics.endFill();
} 

also make sure you have all the correct imports added :)