开发者

Flex: Package is unexpected error

开发者 https://www.devze.com 2022-12-30 20:08 出处:网络
import mx.controls.Alert; package dbconfig // error line here { public class DBConn { private var dbConn:SQLConnection;
import mx.controls.Alert;

package dbconfig // error line here
{
    public class DBConn
    {
        private var dbConn:SQLConnection;
        private var dbFile:File;

     开发者_开发技巧   public function DBConn()
        {
            this.openConnection(); 
        }

        public function openConnection(){
            dbFile = File.applicationStorageDirectory.resolvePath("accounting.sqlite");
            dbConn = new SQLConnection();

            try 
            {
                dbConn.open(dbFile);
                Alert.show("asdf");
            }
            catch(e:SQLError)
            {
                Alert.show("SQL Error Occured: ", e.message);
            }
        }
    }
}


You need to place the import inside of the package definition:

package dbconfig
{
    import mx.controls.Alert;

    public class DBConn
    {
        private var dbConn:SQLConnection;
        private var dbFile:File;

        public function DBConn()
        {
            this.openConnection(); 
        }

        public function openConnection(){
            dbFile = File.applicationStorageDirectory.resolvePath("accounting.sqlite");
            dbConn = new SQLConnection();

            try 
            {
                dbConn.open(dbFile);
                Alert.show("asdf");
            }
            catch(e:SQLError)
            {
                Alert.show("SQL Error Occured: ", e.message);
            }
        }
    }
}


Yes, unlike Java, you must import all classes you are going to use, even if you fully qualify them. Judging by the tags I assume you know this, but the SQLConnection and File are Air only, so wouldn't run in the normal flash player.


crud and sqlite tutorial here: http://www.peterelst.com/blog/2008/04/07/introduction-to-sqlite-in-adobe-air/

0

精彩评论

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