English 中文(简体)
1046:找不到类型毫无意义!
原标题:1046: Type was not found makes no sense!

我有几个定制课程。让我们称之为“Character”,它应该导入并使用“Head”。然后“头”导入并使用“帽子”。这很好。。。

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);      
  }

 }

}

然后头部:

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();   
  }
 }

}

最后是帽子课:

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.

如果我试图定义“Hat”类并在我的主脚本中创建一个“Hat”的新实例,或者在“Hat”中,它就像一个魅力。。。如果我试图用我的“性格”来做这件事,它会给我一个可怕的错误。我检查了我的进口产品,它们都一样!!它到底为什么要这么做?!我真的在这上面浪费了一整天!!!!!

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....

最佳回答

构造函数不应该有返回类型。实例是通过调用构造函数返回的。所以你应该忽略它。这有时会造成问题。

此外,您不必导入与引用它们的类在同一个包中的类。

我尝试过复制和粘贴代码,结果出现了3个错误:

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);
                             ^

如果我删除stageRef和head_text,那么它会编译并运行良好。

您是否尝试删除.swf文件并重新编译?

问题回答

我不确定它是否有意义,但试着重命名你的包(afaik包名称不区分大小写,所以它适合Character类名)

这绝对是一个奇怪的错误,因为它与你的类无关。该错误提到了KeyboardEvent,并且在您的代码中没有它的迹象,也没有需要KeyboardEvent的类的明显迹象。

为了测试起见,您可以更改这一行:

import flash.events.Event;

对此:

import flash.events.*;

当然,这并不能解决问题,但如果错误消失,您可能必须在代码中跟踪此KeyboardEvent。





相关问题
Disable button tooltip in AS3

I want to disable the tooltip on certain buttons. The tooltip manager seems to be an all or nothing solution. Is it possible to disable the tooltip for just one or two buttons?

Sorting twodimensional Array in AS3

So, i have a two-dimensional Array of ID s and vote count - voteArray[i][0] = ID, voteArray[i][1] = vote count I want the top 3 voted items to be displayed in different colors, so i have a 2nd Array -...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

Red5 Security Tutorial

I am looking for a step by step tutorial on securing Red5 from intrusion. This seems to be a question that comes up alot in a google search, but is never really answered in a way that makes sense to ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

visible property of DisplayObject

For example I have a hierarchy of movie clips. mc1 is a child of mc, and mc2 is a child of mc1. Turns out that when I set mc1.visible = false; mc2.visible stays true. Is that supposed to happen?...

热门标签