Apache flex 尝试导入actionscript文件的Flex错误
import Player.as行抛出错误:1084:语法错误:分号前应为rightbraceApache flex 尝试导入actionscript文件的Flex错误,apache-flex,flash,actionscript-3,Apache Flex,Flash,Actionscript 3,import Player.as行抛出错误:1084:语法错误:分号前应为rightbrace package { import "Player.as"; //ERROR import "Card.as"; public class Game { 在我尝试将代码拆分成单独的文件之前,我一直在使用Flex。现在我在挣扎 以下是我的文件及其依赖项: **poker.mxml** include "fb.as"; <mx:Script source="Game.as"/&g
package {
import "Player.as"; //ERROR
import "Card.as";
public class Game {
在我尝试将代码拆分成单独的文件之前,我一直在使用Flex。现在我在挣扎
以下是我的文件及其依赖项:
**poker.mxml**
include "fb.as";
<mx:Script source="Game.as"/>
**Game.as**
import "Player.as";
import "Card.as";
**fb.as**
**Card.as**
**Player.as**
导入声明在包IIRC之前。我猜Player.as和Card.as与Game.as在同一个包中
如果它们在同一个包中,则不需要导入它们。此外,导入语句通常没有.as扩展名。导入时,不使用文件名,而是使用包和类,并且不需要引号:
package
{
import Player;
import Card;
public class Game {}
}
但是,如果它们位于顶层或与正在编辑的类位于同一个包中,则实际上不必导入它们。如果您的玩家和卡牌类别在顶级以外的包中,那么您需要包含该包。下面是一个例子,其中一些任意的包名在我脑海中浮现:
package
{
import com.example.Player;
import com.example.deck.Card;
public class Game {}
}
在MXML中,不包括使用元素源参数的类。实际上,您可以用相同的方式导入它们
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
applicationComplete="applicationCompleteHandler(event)">
<mx:Script><![CDATA[
import com.example.Player;
import mx.events.FlexEvent;
private var _player:Player;
//this event handler is called once the application is fully created
//and drawn for the first time.
private function applicationCompleteHandler(event:FlexEvent):void
{
_player = new Player();
}
]]></mx:Script>
</mx:Application>