简体   繁体   中英

Flex bug trying to import actionscript files

The "import "Player.as" line throws the error: 1084: Syntax error: expecting rightbrace before semicolon.

package {

  import "Player.as"; //ERROR
  import "Card.as";

  public class Game {

I was going great with Flex, until I tried to split up my code into separate files. Now I'm struggling.

Here are my files and their dependencies:

**poker.mxml**

include "fb.as";

<mx:Script source="Game.as"/>

**Game.as**   

import "Player.as";  

import "Card.as";

**fb.as** 

**Card.as** 

**Player.as**

I'm guessing Player.as and Card.as are in the same package as Game.as?

If they're in the same package, you don't need to import them. Also, import statements don't usually have the .as extension.

When importing, you don't use the file name, but the package and class, and no quotes needed:

package
{
    import Player;
    import Card;

    public class Game {}
}

You don't actually have to import them if they're in the top level or the same package as the class you're editing, though. If your Player and Card classes are in packages other than the top level, then you need to include the package. Here's an example with some arbitrary package names that came off the top of my head:

package
{
    import com.example.Player;
    import com.example.deck.Card;

    public class Game {}
}

In MXML, you don't include classes using the element's source parameter. You can import them in the same way, actually.

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

import报关单位于IIRC之前。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM