开发者

Flex bug trying to import actionscript files

开发者 https://www.devze.com 2022-12-18 00:14 出处:网络
The \"import \"Player.as\" line throws the error: 1084: Syntax error: expecting rightbrace before semicolon.

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 declarations come before the package, IIRC.

0

精彩评论

暂无评论...
验证码 换一张
取 消