Hi,
I'm relatively new to AS3, but have a little programming background and some AS2 experience-- but sometimes examples and concepts go over my head.
What I'm trying to do is to create data types for multiple re-use. Say that I'm creating a game, so I want to create a player data type (multiple players), but also things like ship data (multiple ships). I have learned a little C, and in C I would use a struct. In AS3, I though I could use a class, but it's turning out to be more complicated than a simple struct. For one, I cannot put the class into the Flash timeline (confusing). So I created a separate file...
moz.as:
Code:
package moz {
import flash.display.MovieClip;
// Tech list for levels
class ShipList {
var weapon:Number;
var travel:Number;
var shields:Number;
}
// the player class
public class PlayerClass {
var race:Number;
var pname:String;
var money:Number;
var ships:ShipList;
public function PlayerClass() {
money=100;
//
}
}
and then in the timeline for Flash:
Code:
import moz.*;
var player:PlayerClass = new PlayerClass();
var player2:PlayerClass = new PlayerClass();
player.ships.weapon = 1;
player2.ships.weapon = 2;
I could have put the ShipList into the PlayerClass, but I am planning to have many ships, accessed through an array.
There errors I get are:
Quote:
1046: Type was not found or was not a compile-time constant: PlayerClass.
1046: Type was not found or was not a compile-time constant: PlayerClass.
1180: Call to a possibly undefined method PlayerClass.
1180: Call to a possibly undefined method PlayerClass.
|
I could also be setting this up wrong in Flash. I have tried going through the Document Class, but that did not seem to make any difference.
I've search over the web for help, but I always end up with the same examples and I am not sure how to create something I actually want to use.
Any ideas? Is there a better way to create a struct? Help is greatly appreciated.
