;

PDA

Click to See Complete Forum and Search --> : How to not Import Everything?


Zeusbwr
09-11-2006, 12:34 AM
Ok, i've got a fairly simple problem. I don't want to globally open some specific packages. (for name overlapping instances, etc.)

So i simple want to be able to create an object like such:
this.square = new AS.Geo.Square();

But that throws the following error:
**Error** C:\~~\asv301\AS\UIMng\Index.as : Line 10, Column 21 : [Compiler] Error #1046: Type was not found or was not a compile-time constant: Square.
var square:AS.Geo.Square;
ReferenceError: Error #1065: Variable Timeline0_64312f8557c4d469a75a66628e9025 is not defined.

Which confuses me, because it works fine if i import it such as:
import AS.Geo.Square;

So any ideas?

misuser
09-11-2006, 04:29 AM
Importing is not optional in AS3

Zeusbwr
09-11-2006, 11:11 PM
So you must import everything to the class level? You can't cast an object with a reference to where it is located?

misuser
09-12-2006, 04:50 AM
You can import a class (import package.Class) or all the classes within a package (import package.*). What you can't do is have two Classes with the same idenitifier in the same namespace at the same time - which is a good thing.

Zeusbwr
09-12-2006, 10:45 AM
Yea you have to name them correctly, i am with you on that.. but in other languages you can use two of the same class name (ie Square) if you call them from different places.

ie
var blah = new AS.Shapes.Square();
var blah2 = new AS.Objects.Square();


but with imports, that won't work because in terms of each package, you are globally defining the square outside of its own package.. and thus limiting you on names.


Mostly it just kinda sucks if you make a big class, then down the road find out its a name conflict with a class flash already has, but you were just never using that other flash class.

joa__
09-12-2006, 11:53 AM
There is also a missunderstanding in what Adobe calls a namespace and a namespace generally is.

Adobe reference says
- Namespaces of XML objects
- Namespace to differentiate methods
- Namespaces for access control

Cplusplus.com says
Namespaces allow to group entities like classes, objects and functions under a name. This way the global scope can be divided in "sub-scopes", each one with its own name.

Namespaces you may use for classes are public, private and internal.
Functions may use public, private, internal and protected afaik.

misuser
09-12-2006, 01:14 PM
Sorry, I just realised all you need is:

var myFoo:AS.Geo.Square = new AS.Geo.Square();

You forgot to declare your type

misuser
09-12-2006, 01:39 PM
@joa__

I'm not sure I get your point - This is how adobe describe packages...

Packages in ActionScript 3.0 are implemented with namespaces, but are not synonymous with them. When you declare a package, you are implicitly creating a special type of namespace that is guaranteed to be known at compile time.

joa__
09-12-2006, 08:08 PM
It is about terminology. It is a little bit confusing if you have some C++ experience for example. That's all what I wanted to address. Maybe a little bit stupid because I read about namespaces etc. and I thought Zeusbwr was thinking about namespaces as a "Namespace" (which is a new feature of AS3).

Zeusbwr
09-12-2006, 09:24 PM
Sorry, I just realised all you need is:

var myFoo:AS.Geo.Square = new AS.Geo.Square();

You forgot to declare your type

I tried that though.. well ni a different way.

If you look at my example, i declare my object like that
var square:AS.Geo.Square;

and i define it like that also
this.square = new AS.Geo.Square();

(the first being at the top of the class, the 2nd being inside a function in the class)
I should'nt have to declare the variable type twice right? Infact i would imagine that would throw an error.

misuser
09-13-2006, 04:00 AM
Ok so I guess you're doing something like this?


package {
import com.myPackage.Square;
import com.myOtherPackage.Square;

public class myClass
{
public var square1:com.myPackage.Square;
public var square2:com.myOtherPackage.Square;

public function myClass()
{
square1 = new com.myPackage.Square();
square2 = new com.myOtherPackage.Square();
}
}
}


Also remember that class / package name are case sensitive - Also lower case "as" is now a reserved word so that might be causing you problems too

Zeusbwr
09-13-2006, 11:10 PM
Well the import example i gave works just fine.. so i assume the package name is fine.. :/

Dunno, it'll probably work itself out eventually.. thanks :)