View Full Version : Package error
nbyte
07-27-2008, 11:39 AM
Hi.
I'm trying to do simple package using AS 3, but I got problem.
In fla file I typed
include 'unit.as'
and inside unit.as I typed
package simple
{
}
And when I run my project I get error
1037: Packages cannot be nested.
Could someone tell me, please. Why this error happens? :confused:
senocular
07-27-2008, 03:00 PM
packages are used to define definitions like classes. When you use them in your FLA, you do not use include, they are detected automatically by Flash as it reads your filesystem during publish.
nbyte
07-27-2008, 06:05 PM
they are detected automatically by Flash as it reads your filesystem during publish
If I just put *.as inside project folder, Flash doesn't detect them when I publish.
senocular, could you tell me more, about how *.as files are detecting automatically? :confused:
senocular
07-27-2008, 06:28 PM
Could you tell me more, about how *.as files are detecting automatically? :confused:
If I just put *.as inside project folder, Flash doesn't detect them when I publish.
It does, assuming your directory structure matches your package path (if you have one). All you do in the FLA is use your class.
For example, you can have a FLA saved to c:\MyProjects\Project1.fla and a .as class file saved as c:\MyProjects\Ball.as. The Ball class would be defined as
package {
public class Ball {
public function Ball(){
// ball constructor
}
// other ball members
}
}
in the FLA, all you need is
var myBall:Ball = new Ball();
and that's it. The ball class is automatically recognized by Flash and compiled into your SWF.
If the ball is in a package, such as 'simple', then Ball.as will need to be saved in c:\MyProjects\simple\Ball.as and have the package definition package simple {. Then, in the FLA you can still use new Ball but will need to import the class since now it is in a package (and perhaps my original reply could be ammended to include this circumstance)
import simple.Ball;
import is only needed when classes are in packages, though, and really only for AS3. In AS2 you can get away without the import if you use the fully qualified class name: new simple.Ball()... but AS2 only. AS3 requires the import.
nbyte
07-28-2008, 07:37 AM
I tried to do but I got error (I'm using CS3)
In Ball.as I typed
package simple{
public class Ball {
public function Ball(){
trace('Hello');
// ball constructor
}
// other ball members
}
}
In Project1.fla I typed
import simple.Ball;
var myBall:Ball = new Ball();
And when I launch my project I get
5001: The name of package 'simple' does not reflect the location of this file. Please change the package definition's name inside this file, or move the file. E:\Test8\Ball.as
Could you tell me please, how can I correct this situation? :confused:
nbyte
07-29-2008, 07:14 AM
Sorry. But I really don't understand how to solve this problem. :confused:
Does someone know how to solve it?
senocular
07-29-2008, 01:02 PM
Read my last post and read the error. Its all there.
nbyte
07-29-2008, 02:14 PM
I've found my mistake. Now it's correctlly :) .
senocular, thank so much for your help.
senocular
07-29-2008, 03:17 PM
welcome : )
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.