views:

84

answers:

3

I've got several custom classes. Let's call them "Character", which is supposed to import and use "Head". Then "Head" imports and uses "Hat". That works just fine...

package character
{
 import flash.display.MovieClip;
 import flash.events.Event;
 import flash.display.Stage; 
 import flash.display.Sprite;
 import flash.events.Event;
 import character.Head;
 import character.Hat;

 public class Character extends MovieClip 
 {
  // the objects
  public var _head:Head;
            // IF I UNCOMMENT THIS, I GET THIS 1046 ERROR 
  // public var asdfasfd:Hat;

  public function Character():void
  {
   trace("NEW CHARACTER");

   _head=new Head(stageRef, head_text);
   //_shirt=new Shirt(stageRef, shirt);      
  }

 }

}

and then head:

package character
{
 import flash.display.MovieClip;
 import flash.events.Event;
 import flash.display.Stage; 
 import character.Hat;

 // the character's head 
 public class Head extends MovieClip 
 {  
  public var _hat:Hat;  

  function Head(head_type:String=null):void
  {   
   trace ("NEW HEAD");

   this._hat = new Hat();   
  }
 }

}

And finally the hat class:

package character 
{
 import flash.display.MovieClip;
 import flash.events.Event;
 import flash.display.Stage;
 import character.*;

 // the character's head 
 public class Hat extends MovieClip 
 {      
  private var stageRef:Stage;

  function Hat(stageRef:Stage=null, type:String=null):void
  {
   trace ("NEW HAT");
  } 

 }

}

This runs without a hitch. Simple as pie... But if I try to create a new instance of "Hat" or even define the Hat variable in "Character", it gives me the compile time error : 1046: Type was not found or was not a compile-time constant: Hat.

If I try to define "Hat" class and create a new instance of "Hat" in my main script, or in "Hat" it works like a charm... If I try to do it in my "Character" it gives me this godforsaken error. I've checked my imports, they're all the same!! Why in the world is it doing this?! I have literally wasted an entire day on this!!!!!

EDIT / EXTRA INFO: I literally have 5 almost identical classes, like shirt, pants, head, hat, arm... and some of them work, others don't. I copied n' pasted one of the completely generic classes that does work over one that doesn't and still nothing. They're all linked fine and exported for ActionScript... everything's identical, except some work and others dont. But the ones that don't, do work if I include them in the classes that are being called, or anywhere else for that matter... just not in the class I need. I've been on this same thing for 24 hours now. I need a vacation....

A: 

i'm not sure it'll make sense but try to rename your package (afaik package names aren't case sensitive so it fits Character class name)

www0z0k
A: 

It's definitely an odd error as it doesn't relate to your classes. The error mentions a KeyboardEvent and there's no sign of it in your code and no apparent sign of a class which would require a KeyboardEvent.

Just for testing sake, you could change this line:

import flash.events.Event;

To this:

import flash.events.*;

Of course , it doesn't solve the problem but if the error goes away, you may have to track this KeyboardEvent in your code.

PatrickS
A: 

Constructors shouldn't have a return type. The instance is returned by calling the constructor. So you should just leave it out. This can sometimes cause problems.

Also, you don't have to import classes that are within the same package as the class you are referencing them from.

I've tried copying and pasting the code and it gives me 3 errors:

Character.as(22): col: 21 Error: Access of undefined property stageRef.

    _head=new Head(stageRef, head_text);
                   ^

Character.as(22): col: 31 Error: Incorrect number of arguments.  Expected no more than 1.

    _head=new Head(stageRef, head_text);
                             ^

Character.as(22): col: 31 Error: Access of undefined property head_text.

    _head=new Head(stageRef, head_text);
                             ^

If I remove stageRef and head_text then it compiles and runs fine.

Have you tried deleting the .swf files and re-compiling?

Joony
Thanks. I didn't know you didn't have to import classes in the same package. Wish I'd have known that sooner! But the classes that work and don't all have a return type (well, all did. i took them all out and all the imports for the same package... nothing changed)
Cyprus106