Skip to main content
Known Participant
June 16, 2009
Answered

starting with as files

  • June 16, 2009
  • 1 reply
  • 625 views

hi, just the basics of placing code in an as file

i created a file, this is all the code in the file:

package something {      public class some_class {      } }

the file is called 'package_test.as'

now i create a new animation file, and in fort frame i place something like:

include "package_test.as"

import something.*

//

trace("done");

just the basics, create a class inside a packgage with a test clas, then try to recall it from another file. i get the next error:

1037: Packages cannot be nested

i mean, is pretty straight forward, just test the basics of placing code in a file and calling it from another file. it is not because the class is empty or has no constructor, i did this test because i had some code in some movies and i am trying to place them as part of a class, but i am failing in the basics so far. any pointers?

This topic has been closed for replies.
Correct answer Michael Borbor

No an AS3 class file, can only contain a single class. If you don't have a package you have to begin your class like this

package{

    public class MyClass{

          function MyClass(){

      }

}

}

And your file has to be named MyClass.as

1 reply

Michael Borbor
Inspiring
June 16, 2009

Your class name should be the same as your filename. Worth reading this doc.

http://www.flashandmath.com/bridge/intro/class.html

Known Participant
June 16, 2009

not sure about this; according to documentation, in a single as file can be defined more than one classes (unlike as2). also, i tried this:

1. i removed the package tag, so there was only the class defined there

after that it told me the public tag could be used only if defined inside a package, so i removed the public atribute for the class definition

2. i renamed the class so it would be the same as the file name, something like:

//package something {

class package_test {

}

//}

this is the (whole) new content of the file

now i get this:

1131: Classes must not be nested.

there is only one class, named exactly as the file, so i guess this is not it, but tnx anyway

Michael Borbor
Michael BorborCorrect answer
Inspiring
June 16, 2009

No an AS3 class file, can only contain a single class. If you don't have a package you have to begin your class like this

package{

    public class MyClass{

          function MyClass(){

      }

}

}

And your file has to be named MyClass.as